How to test a random generator

前端 未结 12 1192
滥情空心
滥情空心 2020-12-24 01:42

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

12条回答
  •  余生分开走
    2020-12-24 02:03

    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.

提交回复
热议问题