diff options
author | David Mitchell <davem@iabyn.com> | 2015-12-01 12:32:34 +0000 |
---|---|---|
committer | David Mitchell <davem@iabyn.com> | 2015-12-01 12:32:34 +0000 |
commit | 7d9942e329fa0ad09f22c706668103b6a0b73c7c (patch) | |
tree | c472f7be5e0a6d117a3ddbd32b5b6bda52933ace /mg.c | |
parent | 8b002d476a21e6f92b2a461d3255fe50587956ca (diff) | |
download | perl-7d9942e329fa0ad09f22c706668103b6a0b73c7c.tar.gz |
op/rand.t: better test even spread of random nums
The old test evaluated int(256*rand(1)) a large number of times, and
calculated the average number of bits seen in the result. If this was too
far from 4, it failed the (single) test. This is a rather crude test, and
generated what may be false negatives quite often in smoke tests.
This commit replaces that with a more comprehensive test scheme, but which
should cause a false negative in the test script only once every 2 million
runs, assuming a fair random number generator.
As before, it calculates 256*rand(1) many times, but maintains a count of
the number of occurrences of each result. Each count is then checked
whether it is within 6 sigmas of the expected value. For example for
100_000 iterations, we expect each count to be approximately 390, with a
6-sigma range of 272..509. If any count is outside that range, it fails
one of the 256 tests.
Thus this script now does 256 tests rather than a single one, so is a lot
better at detecting bad RNGs.
With each test being 6-sigma (1 in 500e6 failures) and 256 tests, that
gives us a false negative rate of approx 1 in every 2 million runs.
Diffstat (limited to 'mg.c')
0 files changed, 0 insertions, 0 deletions