random number generator test

后端 未结 4 1691
太阳男子
太阳男子 2021-01-03 00:42

How will you test if the random number generator is generating actual random numbers?

My Approach: Firstly build a hash of size M, where M is the prime number. Then

4条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-03 01:07

    Let's say you want to generate a uniform distribution on the interval [0, 1].

    Then one possible test is

    for i from 1 to sample-size
    when a < random-being-tested() < b
    counter +1
    return counter/sample-size
    

    And see if the result is closed to b-a (b minus a).

    Of course you should define a function taking a, b between 0 and 1 as inputs, and return the difference between the counter/sample-size and b-a. Loop through possible a, b, say of the multiples of 0.01, a < b. Print out a, b when the difference is larger than a preset epsilon, say 0.001.

    Those are the a, b for which there are too many outliers.

    If you let sample-size be 5000. Your random-being-tested will be called about 5000 * 5050 times in total, hopefully not too bad.

提交回复
热议问题