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: src/tools/test/devrandom/hammer.urandom,v 1.4 1999/08/28 00:54:24 peter Exp $
9# $DragonFly: src/tools/test/devrandom/hammer.urandom,v 1.2 2003/06/17 04:29:11 dillon Exp $
10#
11
12open(ZERO, "/dev/zero") || die "Cannot open /dev/zero - $!\n";
13
14for (;;) {
15	open(BIN, "/dev/urandom");
16	$len = sysread(BIN, $a, 20);
17	sysread(ZERO, $b, 20);
18	close(BIN);
19	if ($len > 0) {
20		for ($j = 0; $j < $len; $j += 2) {
21			$k = unpack("S", substr($a, $j, 2));
22			$z = unpack("S", substr($b, $j, 2));
23			$z == 0 || die "/dev/zero is returning non-zero!\n";
24			printf("%.4X ", $k);
25		}
26		printf "\n";
27	}
28}
29