http://www.perlmonks.org?node_id=84971

Well, I think it's pretty cool, but I've always liked physics. Chaotic systems are just like pseudorandom numbers only you don't know the seed. But quantum processes can be genuinly random and fundimentally unpredictable.

Fourmilab, where atom-smashing geeks dwell, has a cute toy in the basement. It generates true random numbers based on radioactive decay, and makes data available to the public.

They have a Java package to programmatically access it, but I wanted to do it in Perl. So I wrote a simple Perl module to access the server. I don't know how useful this is for most folks, but hey, it's cool!

—John
(code follows)

sample program

use strict; use warnings; use HotBits; my $x= new HotBits::; my $bits= $x->request (16); # parameter is bytes to fetch, up to 2048 +. print length($bits)," bytes: "; print unpack("H*", $bits), "\n";

HotBits.pm

=head1 NAME B<HotBits> - download hardware random numbers =head1 AUTHOR John M. Dlugosz - john@dlugosz.com - http://www.dlugosz +.com =head1 DESCRIPTION This module will access "genuine" random numbers via http://www.fourmi +lab.ch/hotbits/. This server at Fourmilab in Switzerland uses radioactive decay to offe +r the truest random number source possible. This module works the same as the site's Java + class for the same purpose: access the CGI program via HTTP. =cut package HotBits; use strict; use warnings; our $VERSION= v1.0; require LWP::UserAgent; use Carp; my $serverURL='http://www.fourmilab.ch/cgi-bin/uncgi/Hotbits'; sub new { my $class= shift; my $URL= shift || $serverURL; # optional argument my $ua = new LWP::UserAgent::; $ua->env_proxy(); my $self= bless { ua => $ua, URL => $URL }, $class; return $self; } sub request { my ($self, $count)= @_; $count ||= 128; my $request = HTTP::Request->new('GET', "$self->{URL}?nbytes=$count&f +mt=bin"); $request->proxy_authorization_basic($ENV{HTTP_proxy_user}, $ENV{HTTP_ +proxy_pass}) if $ENV{HTTP_proxy_user}; my $response = $self->{ua}->request($request); croak "Error from $self->{URL}", if ($response->code() != 200); croak "Unexpected return (not binary) from $self->{URL}" if $response +->headers()->content_type() ne "application/octet-stream"; return $response->content(); } 1; # module loaded OK.