xref: /freebsd/tools/test/devrandom/stat.16bit (revision d0b2dbfa0ecf2bbc9709efc5e20baf8e4b44bbbf)
1#!/usr/bin/perl
2
3#
4# Perform primitive binning into 16-bit bins (take 16bits of randomness
5# at a time) and see if the distribution is flat. The output should be
6# checked by eye - are all the numbers roughly the same?
7#
8# Redirect the output from this to a file - and go to the movies while
9# it runs. This program is a CPU Hog!
10#
11#
12
13for ($i = 0; $i < (1024*64); $i++) {
14	open(BIN, "/dev/urandom") || die "Cannot open /dev/urandom - $!\n";
15	$len = sysread(BIN, $a, 512);
16	close(BIN);
17	if ($len > 0) {
18		for ($j = 0; $j < $len; $j += 2) {
19			$k = unpack("S", substr($a, $j, 2));
20			$bin[$k]++;
21		}
22	}
23}
24
25for ($i = 0; $i < 1024*64; $i++) {
26	printf("%.2X ", $bin[$i]);
27}
28printf "\n";
29