[Haskell-beginners] randmomR produces only even values
martin
martin.drautzburg at web.de
Fri Oct 30 18:43:23 UTC 2015
Hello all
When I read:
mkStdGen :: Int -> StdGen
The function mkStdGen provides an alternative way of producing an initial generator, by mapping an Int into a generator.
Again, distinct arguments should be likely to produce distinct generators.
I thought, that
> fst $ R.randomR (1,10) (R.mkStdGen s)
should get me a random value between 1 and 10 and that I get different values depending on the seed s. But this
> length $ filter even $ map (\s -> fst $ randomR (1::Int,10) (mkStdGen s))[1..1000]
gives my 1000, i.e. all random numbers are even numbers.
However, when I use random instead of randomR
> length $ filter even $ map (\s -> fst $ random (mkStdGen s) ::Int)[1..1000]
I get 499 (okay)
Why is that so?
More information about the Beginners
mailing list