How to test a random generator

2019-02-01 18:42发布

I need to test a random number generator which produces numbers randomly. How to make sure the numbers generated are random.

13条回答
够拽才男人
2楼-- · 2019-02-01 19:25

Often if you have your generator draw dots at random locations in a bitmap, any nonrandomness will easily be discernable to the eye as clumping, banding or lines.

查看更多
\"骚年 ilove
3楼-- · 2019-02-01 19:28

It's a very difficult thing.

You may try ENT from Fourmilab and compare it with the results against their RNG, HotBits. You may also like to review Random.org.

This also looks interesting: Diehard tests (I've not worked with it though).

查看更多
Evening l夕情丶
4楼-- · 2019-02-01 19:28

Create a log file which will contains the random number for atleast 500 instances and audit it for randomness. Also have a look at below link,

http://burtleburtle.net/bob/rand/testsfor.html

查看更多
姐就是有狂的资本
5楼-- · 2019-02-01 19:33

There is a good tool for this puprose: http://www.phy.duke.edu/~rgb/General/dieharder.php

for example you can test build-in urandom

cat /dev/random | dieharder -a -g 200

Or write your own script that will create a file with random numbers

dieharder -a -g 202 -f random.txt
查看更多
Ridiculous、
6楼-- · 2019-02-01 19:36

Unless you have access to the random number generator and can use it to generate numbers at will, you can't test if a sequence of numbers is random. Think about it: you have a random number generator. Let's say it's a uniform random number generator, generating random integers in the range [0,9]. Given a sequence:

0, 1, 2, 3, 4, 5, 6, 7, 8, 9

can you tell if it is random? There is a finite probability 10−10, that our uniform random number generator will generate this exact sequence. In fact, given any length-10 sequence, we have the same probability of our uniform random number generator generating that sequence. Hence, by definition, you can't determine if a given sequence is random.

If you do have access to the generator itself, and can use it to generate multiple sequences, then it makes sense to "check for randomness". For this, I would look at Diehard tests. There are various implementations.

查看更多
Explosion°爆炸
7楼-- · 2019-02-01 19:38

It depends how severe your requirement for randomness is. If it is not too severe, what I do is generate a large number of random numbers, find their frequencies and then use the frequencies to plot a graph using a spreadshhet like that in Open Office. If the distribution looks OK, then I'm good to go.

查看更多
登录 后发表回答