www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 14312] New: std.random unittest has intermittent failure

https://issues.dlang.org/show_bug.cgi?id=14312

          Issue ID: 14312
           Summary: std.random unittest has intermittent failure
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P1
         Component: Phobos
          Assignee: nobody puremagic.com
          Reporter: hsteoh quickfur.ath.cx

From the autotester:
------ ****** FAIL release64 std.random core.exception.AssertError std/random.d(2994): 99: 4700 < 4700. ---------------- generated/linux/release/64/unittest/libphobos2-ut.so(void std.random.__unittestL2739_32()+0xe682) [0x2ae3d8e08efe] generated/linux/release/64/unittest/libphobos2-ut.so(void std.random.__modtest()+0x7c) [0x2ae3d8e7c950] generated/linux/release/64/unittest/test_runner() [0x401361] generated/linux/release/64/unittest/libphobos2-ut.so(runModuleUnitTests+0xe1) [0x2ae3d9c96d51] generated/linux/release/64/unittest/libphobos2-ut.so(void rt.dmain2._d_run_main(int, char**, extern (C) int function(char[][])*).runAll()+0x17) [0x2ae3d9cb97bf] generated/linux/release/64/unittest/libphobos2-ut.so(void rt.dmain2._d_run_main(int, char**, extern (C) int function(char[][])*).tryExec(scope void delegate())+0x2d) [0x2ae3d9cb9775] generated/linux/release/64/unittest/libphobos2-ut.so(_d_run_main+0x1ec) [0x2ae3d9cb96ec] generated/linux/release/64/unittest/test_runner() [0x401567] /lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xf5) [0x2ae3da64fec5] make[1]: *** [unittest/std/random.run] Error 1 make[1]: *** Waiting for unfinished jobs.... 5.458s PASS release64 std.datetime 7.936s PASS release64 std.parallelism make[1]: Leaving directory `/home/braddr/sandbox/at-client/pull-1467374-Linux_64_64/phobos' make: *** [unittest-release] Error 2 ------ Looking at the code, the offending line is buried deep inside a unittest: ------ /* Statistical assumptions here: this is a sequential sampling process * so (i) 0 can only be the first sample point, so _can't_ be in the * remainder of the sample after .popFront() is called. (ii) By similar * token, 1 can only be in the remainder if it's the 2nd point of the * whole sample, and hence if 0 was the first; probability of 0 being * first and 1 second is 5/100 * 4/99 (thank you, Algorithm S:-) and * so the mean count of 1 should be about 202. Finally, 99 can only * be the _last_ sample point to be picked, so its probability of * inclusion should be independent of the .popFront() and it should * occur with frequency 5/100, hence its count should be about 5000. * Unfortunately we have to set quite a high tolerance because with * sample size small enough for unittests to run in reasonable time, * the variance can be quite high. */ assert(count0 == 0); assert(count1 < 300, text("1: ", count1, " > 300.")); assert(4_700 < count99, text("99: ", count99, " < 4700.")); // <--- FAILURE HERE assert(count99 < 5_300, text("99: ", count99, " > 5300.")); ------ The comment about statistical assumptions appear to be contradicted by the test results. Unfortunately I do not have the RNG know-how to understand what went wrong here. This bug is not easy to reproduce, since it depends on the exact sequence of random numbers generated by the RNG being tested. --
Mar 20 2015