haskell - Generate N random numbers using randomR -


I want to randomize the random number using randomR.

I know that there are other ways to use randomRs and complete this as taking this code as N:

  Diff_select :: int - & gt; Int - & gt; StdGen - & gt; [Int] diff_select nm = take N digits RandomRs (1, m)  

but I use randomR and Want to use state I'm not sure where I am with this code:

  let's FS = \ s -> (Random R (0, 5) S, S) should give the status s = State (FS) representative N MA = Repell MN (theState ma) let res = runState (rep3) (mkStdGen 4) - want to use  state  to generate random numbers while using <`> 

, You want your state to be generator. In this situation, we can only use the StdGen :

  type RandGen a = State StdGen a  

then you Write a task to create a single random value

  getRandom :: Random A => RandGen a getRandom = do gen & lt; - get (val, newGen) = new genera return value to random generic  

You can now use it to make all random numbers all the normal monaad functions, such as Sequence , mapM , etc. I will let you implement this part. Finally, you just have to execute the code:

  & gt; RunState getRandom (mkStdGen 42) :: (Int, StdGen)  

If you want to make it even easier, then the following types in the state function Are:

  state :: MonadState sm => (S -> (A, S)) - & gt;   

and random type

  random :: (Random A, Randgen G) => G - & gt; (A, G)  

Note how s and g appear here? You actually receive getRandom by

  getRandom :: Random a => Can change RandGen is a getRandom = state random  

and all your hard work is done for you.


Comments

Popular posts from this blog

winforms - C# Form - Property Change -

java - Messages from .properties file do not display UTF-8 characters -

javascript - amcharts makechart not working -