How to test a random generator

前端 未结 12 1144
滥情空心
滥情空心 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:14

    You cannot ensure the numbers are random simply because random numbers are, well, random.

    The chances of getting a string of one million consecutive 9's is the same as getting any other specific one-million-long sequence. The one thing you can check for is correct distribution over a large sample set. Run a sizeable test and work out the relative occurrences of each possible outcome.

    Over a large enough sample, they should be roughly the same.

    One other possibility is to test for non-repeatability. Ideally, random numbers should not depend on the numbers that came before. Very simple (linear congruential) PRNGs will most likely give you the same sequence of numbers eventually but over a large enough set that you probably won't care (unless you're serious about randomness).

提交回复
热议问题