<div dir="ltr">I've replicated this and it does seem very strange, and possibly even a bug.<div><br></div><div>I would guess that most people don't encounter this issue as a generator is usually only seeded once, then threaded throughout generation. Not seeded for once for every random output. The other common practice is that generators are usually seeded on far more random input values than a list of ascending ints.</div><div><br></div><div>Seed behaviour:</div><div><br></div><div><div> main = mapM_ print (map p l)</div><div> p x = length $ filter even $ map (\s -> fst $ randomR (1::Int,10) (mkStdGen s)) x</div><div> l = map ls [1..10]</div><div> ls x = map (\y -> x * y * 10) [1..1000]</div></div><div><br></div><div><div> 1000</div><div> 1000</div><div> 1000</div><div> 1000</div><div> 1000</div><div> 894</div><div> 766</div><div> 670</div><div> 596</div><div> 536</div></div><div><br></div><div><br></div><div>Still, I am very surprised by this behaviour. I couldn't find any reference to this behaviour in[1], which is supposedly what the System.Random implementation is based on.</div><div><br></div><div>Does anyone else have an explanation?</div><div><br></div><div><div><br></div><div> - Lyndon</div></div><div><br></div><div><br></div><div>[1] - <a href="https://en.wikipedia.org/wiki/Linear_congruential_generator">https://en.wikipedia.org/wiki/Linear_congruential_generator</a></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Sat, Oct 31, 2015 at 5:43 AM, martin <span dir="ltr"><<a href="mailto:martin.drautzburg@web.de" target="_blank">martin.drautzburg@web.de</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hello all<br>
<br>
<br>
When I read:<br>
<br>
mkStdGen :: Int -> StdGen<br>
<br>
The function mkStdGen provides an alternative way of producing an initial generator, by mapping an Int into a generator.<br>
Again, distinct arguments should be likely to produce distinct generators.<br>
<br>
I thought, that<br>
<br>
> fst $ R.randomR (1,10) (R.mkStdGen s)<br>
<br>
should get me a random value between 1 and 10 and that I get different values depending on the seed s. But this<br>
<br>
> length $ filter even $ map (\s -> fst $ randomR (1::Int,10) (mkStdGen s))[1..1000]<br>
<br>
gives my 1000, i.e. all random numbers are even numbers.<br>
<br>
However, when I use random instead of randomR<br>
<br>
> length $ filter even $ map (\s -> fst $ random (mkStdGen s) ::Int)[1..1000]<br>
<br>
I get 499 (okay)<br>
<br>
Why is that so?<br>
_______________________________________________<br>
Beginners mailing list<br>
<a href="mailto:Beginners@haskell.org">Beginners@haskell.org</a><br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners</a><br>
</blockquote></div><br></div>