This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
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.