#!/usr/bin/perl

use strict;
use Symbol qw();

my $random_bytes = 16;

sub make_random_cookie
{
	my $bytes = shift;

	my $fh = Symbol::gensym();
	open($fh, "</dev/urandom")
		or die "could not open /dev/urandom for reading: $!";

	my $buf;
	sysread($fh, $buf, $bytes);
	my @bytes = unpack("C*", $buf);
	my $cookie = sprintf("%02x" x scalar(@bytes), @bytes);

	die "unable to read sufficent information from /dev/urandom"
		if ( length($cookie) != $bytes*2 );

	return $cookie;
}

print "random cookie = " . make_random_cookie($random_bytes) . "\n";





