I know how to generate a single random number within a given range, a list of random numbers, a list which contains a given number of random numbers but NOT a list which contains a given number of random numbers within a RANGE. Can anyone help me on this?
This code (extracted from haskell.org) generates a list of 10 random numbers, but I need to give a range, any ideas on how to edit this to give a range?
import System.Random
import Data.List
main = do
seed <- newStdGen
let rs = randomlist 10 seed
print rs
randomlist :: Int -> StdGen -> [Int]
randomlist n = take n . unfoldr (Just . random)
randomList :: (Random a) => (a,a) -> Int -> StdGen -> [a]
randomList bnds n = take n . randomRs bnds
Using randomRs
from System.Random
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With