4 ms·
I’m curious about that too. How could you unit/regression test `rand`?
by jackweirdy 12y ago
I’m curious about that too. How could you unit/regression test `rand`?
- fixermark 12y agoStatistic testing seems like it ought to work. However, I believe there's also the issue of actual uses of the RNG; it's not enough to test the kernel implementation, one must also test that libraries are using the implementation correctly (i.e. not using constant or completely-predictable seed), etc. So it's not a trivial problem, because (among other reasons) nondeterministic, statistical testing is not well-understood in the testing culture.
- tedunangst 12y agoFurther complication: many RNGs will produce output as a function of their seed state (e.g., rc4 or chacha20). That output will look really good, even with weak seeds. You'll have a hard time detecting that two chacha20 streams were seeded with gettimeofday() for instance, unless you happen to check the exact time used.
- jwiley 12y agoassert(rand() != dummy_random_read_phony())
- tedunangst 12y agoIf dummy_random_read_phony() is rand(), that test will always pass. Almost every implementation of rand() will never return the same result in a row.
- rnnr 12y agoYou use statistics. For example, take the birthday paradox problem and check if the collisions are higher than expected.
- tedunangst 12y agoeh, I'm not sure that works. A random number generator of "return number++" will pass your birthday test.
- rnnr 12y agoI just gave an example. I never intended to say you just need this sole solution. It's also a good lead for a further search query on the topic. Almost all test sets include a birthday test ;) For example this page: https://sites.google.com/site/astudyofentropy/background-information/the-tests https://sites.google.com/site/astudyofentropy/background-inf...