112059Smarkm#!/usr/bin/perl
212059Smarkm
312059Smarkm#
412059Smarkm# Perform primitive binning into 8-bit bins (take 8 bits of randomness
512059Smarkm# at a time) and see if the distribution is flat. The output should be
612059Smarkm# checked by eye - are all the numbers roughly the same?
712059Smarkm#
812059Smarkm# Redirect the output from this to a file - and make a cup of coffee while
912059Smarkm# it runs. This program is a CPU Hog!
1012059Smarkm#
1150477Speter# $FreeBSD$
1212059Smarkm#
1312059Smarkm
1412059Smarkmfor ($i = 0; $i < (1024*32); $i++) {
1512059Smarkm	open(BIN, "/dev/urandom") || die "Cannot open /dev/urandom - $!\n";
1612059Smarkm	$len = sysread(BIN, $a, 256);
1712059Smarkm	close(BIN);
1812059Smarkm	if ($len > 0) {
1912059Smarkm		for ($j = 0; $j < $len; $j++) {
2012059Smarkm			$k = unpack("C", substr($a, $j, 1));
2112059Smarkm			$bin[$k]++;
2212059Smarkm		}
2312059Smarkm	}
2412059Smarkm}
2512059Smarkm
2612059Smarkmfor ($i = 0; $i < 256; $i++) {
2712059Smarkm	printf("%.2X ", $bin[$i]);
2812059Smarkm}
2912059Smarkmprintf "\n";
30