xref: /freebsd/tools/test/devrandom/hammer.urandom (revision 924226fba12cc9a228c73b956e1b7fa24c60b055)
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# $FreeBSD$
9#
10
11open(ZERO, "/dev/zero") || die "Cannot open /dev/zero - $!\n";
12
13for (;;) {
14	open(BIN, "/dev/urandom");
15	$len = sysread(BIN, $a, 20);
16	sysread(ZERO, $b, 20);
17	close(BIN);
18	if ($len > 0) {
19		for ($j = 0; $j < $len; $j += 2) {
20			$k = unpack("S", substr($a, $j, 2));
21			$z = unpack("S", substr($b, $j, 2));
22			$z == 0 || die "/dev/zero is returning non-zero!\n";
23			printf("%.4X ", $k);
24		}
25		printf "\n";
26	}
27}
28