简体   繁体   中英

random number generator in Haskell

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 lh num = take num (map (rand lh) [0..])

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM