How to Use OpenCV to Test Pseudo Random Number Generator



Human eye is very good detecting patterns

Most of the (pseudo) random number generators do not actually generate random series but something that is good enough for average purposes.

One of the easiest ways to detect flaws is to measure the distances of same random number in a long series of numbers.

The most common distances are the shortest ones, the longer the distance the less common it is; this is simplified version of the truth - easy to understand.

We took the standard (Windows) rand() function (known to have issues) and plotted the distance distribution into a grayscale image.

Generator generates 2^30 random numbers and plots the distance to last one in a bitmap which then is stored to a PNG file, JPG is not good since the compression "smoothens" the image.