Testing random

Christian Gollwitzer auriocus at gmx.de
Sun Jun 7 08:53:22 EDT 2015


Am 07.06.15 um 08:27 schrieb Cecil Westerhof:
> I wrote a very simple function to test random:
>      def test_random(length, multiplier = 10000):
>          number_list = length * [0]
>          for i in range(length * multiplier):
>              number_list[random.randint(0, length - 1)] += 1
>          minimum = min(number_list)
>          maximum = max(number_list)
>          return (minimum, maximum, minimum / maximum)
>

> It shows that when the first parameter increases the deviation
> increases and when the second parameter increases the deviation
> decreases. Exactly what you would expect. But what are the ranges you
> would expect with a good random function. Then it could be used to
> test a random function.

Random number generators (RNG or PRNG) are usually tested using similar 
methods, where the outcome can be assigned a probability distribution. 
For example, diehard is a famous sequence of tests for RNGs.

http://en.wikipedia.org/wiki/Diehard_tests

You are only checking for uniform distribution. This couldn't detect 
correlation, for instance if the RNG would just return increasing 
numbers. A better check for uniformness could be done by the chi square 
test or Kolmogorov-Smirnov. Then there are tables which relate the 
deviations to significance.

	Christian



More information about the Python-list mailing list