It's an implementation of Benford's Law -- in a large collection of
numbers reflecting measurement of some value, the average occurance of
leading digits being '1' is log(2)/log(n) in base-n notation. In base
2 it's trivial. (All number must start with one except 0.) This program
checks that and then more. It also checks for convergence to just a flat
random variable, which has equal probability from '1' to '9', and it
watches out for not having enough statistics. If you supply a random
number generator to the program as in the README file, most of the time 
it will figure out it's a random number (if the sequence is at least
600 lines long).

Benford's law tends to be VERY accurate for physical data like in a
laboratory notebook(I took all my lab data and scan it through and it
works -- proof that I'm an honest scientist.) For a large collection of
sociological or economics data it also works well. (I have downloaded
the census of Thailand household income and US labor force level since
1940's and they both work) `du` or `ls -l` should work well too, as the
filesize is a measure, although `ls -l` result can be somewhat skewed
by the date and time as the hour hovers only around 1 and 2. The beauty
of all this is that it doesn't care what these numbers are measuring,
or if they are measuring the same quantity at all! (You can combine
a table of the US's per town/city toilet seat count to the luminosity of all
known stars in our galaxy). This law could be turned around to spot 
unwary tax evaders, commercial fraud, etc. (It has been done.) Feels 
like having God's eye, eh?

Armed with this information, the program is actually not so difficult.
The whole point is to do statistics of the leading digits, which perl is
very good at. Although I throw in some obfuscation to shorten the code
below the 512 byte limit rather than to make it really hard to 
understand, in fact, it's exactly 512 bytes long  -- I guess the idea 
of textual code reuse isn't so bad, (but probably not new?).

Unabridged code is like this (still pretty short):

#!/usr/bin/perl

# check a file for accordance to Benford's Law
# basically, the frequency of having d as the leading digit of
# numbers is log(1+1/d)/log(10) -- 30% for '1'.

$b = 10; 
@d = (); 
$t=0; # how many numbers in the input
$s=0; # deviation from Benford's Law
$u=0; # deviatioin from random numbers
for(0..$b-2) { push @d, 0; } # make an array
while(<>) {
	s/e[+-]?|\.//ig;
	for(/([1-9])\d*/g) { $d[$_-1]++; } # count the leading digits
}
for(@d) {$t+=$_;}
for(0..$b-2) { 
	$s+=(log(1+1/($_+1))/log($b)-$d[$_]/$t)**2/($b-1);
        $u+=(1/($b-1)-$d[$_]/$t)**2/($b-1);
}
$s/=10;
print "$s\t$u\n";
$v = log(2)/log($b)/$t; # perfect limit for random, roughly OK for Benford's
if ($u<$v && $s<$v) {
        print "Can't really tell. Give me more numbers.\n";
} elsif ($u<$v) {
        print "Random numbers?\n";
} elsif ($s<$v) {
        print "A collection of measured data?\n";
} else {
        print "Fudged data?\n";
}

