Random Number Generation SIMPLE

I am writing this after a good study of disappointment, and I hope that someone here can tell me about the topic.

I want to create a prime random number in the haskell function, but, alas, it is impossible to do without any non-trivial elements like Monads, asignation in the "do", creating generators, etc.

Ideally, I was looking for the equivalent of C "rand ()". But after a long search, I am quite sure that there is no such thing, because of how the language is developed. (If there is, please someone enlighten me). Since this is not possible, I would like to find a way to get a random number for my specific problem and a general explanation of how this works to get a random number.

prefixGenerator :: (Ord a, Arbitrary a) => Gen ([a],[a])
prefixGenerator = frequency [ 
    (1, return ([],[])),
    (2, do {
            xs1 <- orderedListEj13 ;
            xs2 <- orderedListEj13 ;
            return (xs1,xs2)
       }),
    (2, do {                
            xs2 <- orderedListEj13 ;
            return ((take RANDOMNUMBERHERE xs2),xs2)
       })
    ]

QuickCheck, . - this ( drawInt 0 ( xs2) RANDOMNUMBERHERE), , Int IO Int, Int this.

+5
3

haskell - , , , , . , , .

, - :

prefixGenerator :: (Ord a, Arbitrary a) => Gen ([a],[a])
prefixGenerator = do
  randn <- choose (1,999) -- number in range 1-999
  frequency [ 
    (1, return ([],[])),
    (2, do {
            xs1 <- orderedListEj13 ;
            xs2 <- orderedListEj13 ;
            return (xs1,xs2)
       }),
    (2, do {                
            xs2 <- orderedListEj13 ;
            return ((take randn xs2),xs2)
       })
    ]

haskell IO, PRNG, , IO ( gspr ).

, , System.Random, this ( ).

+6

( "" ) . Haskell , , .

, , , PRNG. , , QuickCheck "" , .

mkStdGen System.Random. Haskell wiki:

import System.Random
import Data.List

randomInts :: Int -> [Int]
randomInts n = take n $ unfoldr (Just . random) (mkStdGen 4)

4 - , .

+4

. , , next, Int Int , :

next :: Int -> Int
randoms :: [Int]
randoms = iterate next 73

, .

Here's a linear congruent nextfrom Wikipedia:

next n = (1103515245 * n + 12345) `mod` 1073741824

And here are the first 20 pseudorandom numbers following 73:

Prelude> take 20 $ iterate next 73
[73,25988430,339353199,182384508,910120965,1051209818,737424011,14815080,325218177,1034483750,267480167,394050068,4555453,647786674,916350979,980771712,491556281,584902142,110461279,160249772]
+3
source

All Articles