Reputation: 2759
I am trying to generate 10 random numbers in Haskell mkStdGen
in the range of 0 (inclusive) to 100 (exclusive).
Something equivalent of the following Java code
Random ran = new Random();
ran.nextInt(100);
Note, I have to use mkStdGen
This is what I have so far
rand low high seed = fst (randomR (low, high) (mkStdGen seed))
randomlist :: Int -> Int -> Int -> [Int]
randomlist l h num = take num (map (rand l h) [0..])
Upvotes: 1
Views: 5991
Reputation: 47042
import System.Random
tenPseudorandomNumbers :: Int -> [Int]
tenPseudorandomNumbers seed = take 10 . randomRs (0, 99) . mkStdGen $ seed
Note that this isn't really pseudorandom, because mkStdGen
takes an explicit seed. newStdGen
would be better, if you're allowed to run in IO
.
Upvotes: 6