GHC: Ticket #3620: The seeds generated by split are not independent <p> Suppose we split a seed into two like this: </p> <pre class="wiki">split' :: StdGen -&gt; (StdGen, StdGen) split' g = (g12, g21) where (_, g12) = split g1 (g21, _) = split g2 (g1, g2) = split g </pre><p> Since g1 and g2 are independent, g12 and g21 ought to be too. But they're not! If we use both of g12 and g21 to generate a random number in the range [0..10], then the two numbers ought to be equal 1/11 of the time. In fact, they're never equal. Here is a test program that ought to return True 1/11 of the time but actually always returns False: </p> <pre class="wiki">sample :: StdGen -&gt; (Int, Int) sample g = (fst (randomR (0, 10) g1), fst (randomR (0, 10) g2)) where (g1, g2) = split' g test :: StdGen -&gt; Bool test g = fst (sample g) == snd (sample g) </pre><p> I attached a program that prints the distribution of values from <tt>test</tt> for other ranges than [0..10]. The distribution is always quite bad no matter what the range is. </p> <p> The upshot of all this is that the following <a class="missing wiki">QuickCheck?</a> (version 2) property always passes, even though it's false: </p> <pre class="wiki">import Test.QuickCheck import Text.Show.Functions newtype Eleven = Eleven Int deriving Eq instance Arbitrary Eleven where arbitrary = fmap Eleven (choose (0, 10)) prop :: (Int -&gt; Eleven) -&gt; Bool prop f = f 5 /= f 6 </pre> en-us GHC Trac 1.0.1 NickSmallbone Wed, 28 Oct 2009 15:08:07 GMT attachment set <ul> <li><strong>attachment</strong> set to <em>RandomnessTest2.hs</em> </li> </ul> Ticket simonpj Wed, 28 Oct 2009 15:58:02 GMT difficulty set <ul> <li><strong>difficulty</strong> set to <em>Unknown</em> </li> </ul> <p> Indeed that looks bad. </p> <p> This is a Random library problem, like <a class="new ticket" href="" title="bug: mkStdGen and split conspire to make some programs predictable (new)">#3575</a>. Can anyone help fix it, please? It would make sense to tackle <a class="new ticket" href="" title="bug: mkStdGen and split conspire to make some programs predictable (new)">#3575</a> at the same time. </p> <p> Simon </p> Ticket igloo Fri, 30 Oct 2009 20:48:25 GMT milestone set <ul> <li><strong>milestone</strong> set to <em>_|_</em> </li> </ul> Ticket rrnewton Mon, 27 Jun 2011 01:23:58 GMT owner, failure set <ul> <li><strong>owner</strong> set to <em>rrnewton</em> </li> <li><strong>failure</strong> set to <em>None/Unknown</em> </li> </ul> Ticket nfrisby Wed, 06 Nov 2013 19:59:19 GMT <p> Are there any plans to adopt the work out of Chalmers from the tf-random package on Hackage into System.Random? </p> Ticket