Testing randomness

[email protected] (David Cantrell) Thu, 23 Oct 2003 10:48:01 +0100
Newsgroups perl.crypto
Message-ID <[email protected]>
Haven't seen much traffic here since I subscribed, but it seems like the
most likely place to get help with my little problem.

I recently released Net::Random to the CPAN.  It retrieves data from
online sources of truly random data (so they claim).  I'm quite happy to
believe that those data really are random, but I'm not so happy to
believe that the results of my module are random, because I do some
processing of the data to ensure that the user only gets random values
in a range he has specified.  Any error in my code - off-by-one errors
for instance - could introduce bias.

So, how do I test that the data I produce is random?

Statistics::ChiSquare was my first thought.  However, it has two
problems.  First, from what I can tell, it thinks that a coin tossed one
thousand times that first produces 500 heads then 500 tails is probably
random.  Such a coin is almost certainly not random.  Second, because it
uses a pre-computed table rather than *really* doing a chi-square test,
it won't work for more than 21 data points.  That's a big problem
because I'm pretty happy about the correctness of my data for
single-byte values, it's when I'm giving the user results from larger
ranges - eg random numbers between 10,000 and 30,000 - that I'm worried.
Obviously, to give it a significant amount of data to work with over
such a large range, I need well over 21 values!

Can anyone think of any useful modules for testing both that my data is
evenly distributed, and that it is not predictable?  Otherwise I'm going
to have to dig out my old Stats text books and patch
Statistics::ChiSquare to do the hard sums when necessary.

-- 
David Cantrell | Reality Engineer, Ministry of Information

    I often think that if we Brits had any gratitude in our hearts, we
    would put up a statue to Heinz Guderian - who probably saved us from
    ruin by booting our Army off the continent before we could do
    ourselves real harm.
       -- Mike Stone, in soc.history.what-if