Microsoft Interview Question
Software Engineer / DevelopersCountry: United States
That's not easy. I would look up a number of tests that a random number generator is expected to pass. There's all kinds of stuff. One simple one is to use it to generate random numbers that are, say, integers between 0 and 100, and make sure that the distribution of these numbers is even. You could do a chi-squared test to make sure any observed departures from an even distribution are not statistically significant.
no test can gurantee a random number generator to be truly random, as results are supposed to be random . a binary random number generator could still be good one if it gives 1 (from 0,1) all the million times.
Now that was theory, practically you have to first define some test criteia, like if you run n number of times then the diff in maximum and minimum count of result should not be more then n/10 etc
Using a distribution plotter.
- at November 13, 2011For a random number generator in range [a,b]
Make a-b as y axis
Make function call number / time as x axis.
Make sure they don't look too concentrated in any given region.