xref: /dflybsd-src/tools/test/devrandom/hammer.random (revision c311ab1309381df18f36a2068699f605abbfee74)
1*c311ab13SSascha Wildner#!/usr/bin/env perl
2984263bcSMatthew Dillon
3984263bcSMatthew Dillon#
4984263bcSMatthew Dillon# Test program for /dev/random
5984263bcSMatthew Dillon# Read and display random numbers.
6984263bcSMatthew Dillon# Try tapping shift/alt/ctrl to get more randomness.
7984263bcSMatthew Dillon#
8984263bcSMatthew Dillon# $FreeBSD: src/tools/test/devrandom/hammer.random,v 1.4 1999/08/28 00:54:24 peter Exp $
9984263bcSMatthew Dillon#
10984263bcSMatthew Dillon
11984263bcSMatthew Dillonfor (;;) {
12984263bcSMatthew Dillon	open(BIN, "/dev/random") || die "Cannot open /dev/random - $!\n";
13984263bcSMatthew Dillon	$len = sysread(BIN, $a, 128);
14984263bcSMatthew Dillon	close(BIN);
15984263bcSMatthew Dillon	if ($len > 0) {
16984263bcSMatthew Dillon		print "$len bytes read: ";
17984263bcSMatthew Dillon		for ($j = 0; $j < $len; $j++) {
18984263bcSMatthew Dillon			$k = unpack("C", substr($a, $j, 1));
19984263bcSMatthew Dillon			printf("%.2X ", $k);
20984263bcSMatthew Dillon		}
21984263bcSMatthew Dillon		printf "\n";
22984263bcSMatthew Dillon	}
23984263bcSMatthew Dillon}
24