xref: /freebsd/tools/test/devrandom/hammer.urandom (revision d0b2dbfa0ecf2bbc9709efc5e20baf8e4b44bbbf)
1#!/usr/bin/perl
2
3#
4# Test program for /dev/urandom
5# Read and display random numbers.
6# This also reads /dev/zero to make sure there is no brokenness there.
7#
8#
9
10open(ZERO, "/dev/zero") || die "Cannot open /dev/zero - $!\n";
11
12for (;;) {
13	open(BIN, "/dev/urandom");
14	$len = sysread(BIN, $a, 20);
15	sysread(ZERO, $b, 20);
16	close(BIN);
17	if ($len > 0) {
18		for ($j = 0; $j < $len; $j += 2) {
19			$k = unpack("S", substr($a, $j, 2));
20			$z = unpack("S", substr($b, $j, 2));
21			$z == 0 || die "/dev/zero is returning non-zero!\n";
22			printf("%.4X ", $k);
23		}
24		printf "\n";
25	}
26}
27