2

I've written a Java class for 128-bit floating-point arithmetic. Among other methods, it has a method intended to generate a pseudo-random value in the range [0, 1.0). Although I use the standard java.util.Random class that I consider reliable enough, the way I construct the value of my Quadruple class from it, may occur erroneous. So I'd like to make sure that the random values it returns are random enough. I've checked the distribution of the magnitudes over 10_000 subranges with the Chi-Square criteria, and checked the frequencies of 1 in each bit position of the mantissa, and I've looked at the hexadecimal representations of the numbers with the naked eye, that's all I could think of. So far everything looks quite well.

But these tests don't check many other possible flaws of the pseudo-random numbers (say, a potentially possible correlations between the bits of the mantissa or simply repetition of a short sequence of values). Are there any ways to test a sequence of such numbers more carefully and comprehensively? In case it's relevant to the question, the value of a number of this type is internally stored as 128 bits (two longs) of the mantissa and 32 bits of the exponent.

m. vokhm
  • 669
  • 1
  • 6
  • 24
  • 1
    The referenced paper may help: https://security.stackexchange.com/a/83257 . There is a PDF download. –  Jun 04 '21 at 15:52
  • @Andy thanks, I'll read it (if it's not too scientific for me) – m. vokhm Jun 04 '21 at 16:07
  • 1
    At a minimum it gives you a comprehensive list of tests and descriptions. It would be a great Java library to implement based on its content. The distribution appears to include a 'c' implementation. Here's a git project also implemented in C: https://github.com/greendow/A-variant-of-NIST-SP-800-22-test-suit –  Jun 04 '21 at 16:24

1 Answers1

1

always when I deal with custom or own PRNG I do this:

  1. check histogram

    This will confirm the randomness distribution... so Simply create bins for your range and count how many PRNG numbers hit each bin in N points and then plot the result

  2. do a "randomness" plot

    Simply do a 2D dots plot where x axis is iteration (or order number/index) and y axis is the PRNG value. Something like this:

    for (x=0;x<100000;x++)
       {
       y=Random();
       RenderPixel(x*xscale,y*yscale,some_color);
       }
    

    This will produce image in which you can very easily spot repetitive patterns (in case PRNG has wrong configuration). Here example for simple unsigned integer PRNG from this answer:

    uint PRNG

You can do a combined plot along with computing basic statistical properties to check the quality of PRNG. This is example of it from one of my ancient school projects I coded ages ago:

PRNG plots

Green dots are the "randomness" plot, Aqua is desired distribution and Yellow is histogram. In case you see mostly white frames in that animated GIF download it and view it in picture viewer (as Brownsers has added another GIF decoding bug lately)

Spektre
  • 49,595
  • 11
  • 110
  • 380