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)
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";
=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.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Genuine Quantum Randomness
by dws (Chancellor) on Jun 01, 2001 at 23:03 UTC | |
by John M. Dlugosz (Monsignor) on Jun 01, 2001 at 23:08 UTC | |
by d4vis (Chaplain) on Jun 01, 2001 at 23:36 UTC | |
by John M. Dlugosz (Monsignor) on Jun 02, 2001 at 00:22 UTC | |
by tye (Sage) on Jun 02, 2001 at 00:31 UTC | |
| |
Re: Genuine Quantum Randomness
by knobunc (Pilgrim) on Jun 04, 2001 at 16:39 UTC |