xref: /dflybsd-src/tools/test/devrandom/hammer.urandom (revision c311ab1309381df18f36a2068699f605abbfee74)
1*c311ab13SSascha Wildner#!/usr/bin/env perl
2984263bcSMatthew Dillon
3984263bcSMatthew Dillon#
4984263bcSMatthew Dillon# Test program for /dev/urandom
5984263bcSMatthew Dillon# Read and display random numbers.
6984263bcSMatthew Dillon# This also reads /dev/zero to make sure there is no brokenness there.
7984263bcSMatthew Dillon#
8984263bcSMatthew Dillon# $FreeBSD: src/tools/test/devrandom/hammer.urandom,v 1.4 1999/08/28 00:54:24 peter Exp $
9984263bcSMatthew Dillon#
10984263bcSMatthew Dillon
11984263bcSMatthew Dillonopen(ZERO, "/dev/zero") || die "Cannot open /dev/zero - $!\n";
12984263bcSMatthew Dillon
13984263bcSMatthew Dillonfor (;;) {
14984263bcSMatthew Dillon	open(BIN, "/dev/urandom");
15984263bcSMatthew Dillon	$len = sysread(BIN, $a, 20);
16984263bcSMatthew Dillon	sysread(ZERO, $b, 20);
17984263bcSMatthew Dillon	close(BIN);
18984263bcSMatthew Dillon	if ($len > 0) {
19984263bcSMatthew Dillon		for ($j = 0; $j < $len; $j += 2) {
20984263bcSMatthew Dillon			$k = unpack("S", substr($a, $j, 2));
21984263bcSMatthew Dillon			$z = unpack("S", substr($b, $j, 2));
22984263bcSMatthew Dillon			$z == 0 || die "/dev/zero is returning non-zero!\n";
23984263bcSMatthew Dillon			printf("%.4X ", $k);
24984263bcSMatthew Dillon		}
25984263bcSMatthew Dillon		printf "\n";
26984263bcSMatthew Dillon	}
27984263bcSMatthew Dillon}
28