Skip Menu |

This queue is for tickets about the Net-Random CPAN distribution.

Report information
The Basics
Id: 77201
Status: resolved
Priority: 0/
Queue: Net-Random

People
Owner: Nobody in particular
Requestors: israel.fimbres [...] gmail.com
Cc:
AdminCc:

Bug Information
Severity: Wishlist
Broken in: (no value)
Fixed in: (no value)



Subject: Net::Random qrng.anu.edu.au data source.
I was messing with your Net::Random module yesterday, I got lots of fun and a new working online random data source http://qrng.anu.edu.au/RawHex.php, so I wrote some few tests to prove it performed correctly and I thought that you could probably find my additions useful. Regards, Israel Fimbres D.
Subject: Net-Random-2.1.patch
diff --git a/lib/Net/Random.pm b/lib/Net/Random.pm index 32668ae..067693d 100644 --- a/lib/Net/Random.pm +++ b/lib/Net/Random.pm @@ -62,7 +62,28 @@ my $ua = LWP::UserAgent->new( } map { hex } split(/\s+/, $response); - } } + } }, + 'qrng.anu.edu.au' => { pool => [], retrieve => sub { + my $ssl = shift; + my $response = $ua->get( + ($ssl ? 'https' : 'http') . + '://qrng.anu.edu.au/RawHex.php' + ); + + if ( ! $response->is_success ) { + warn "Net::Random: Error talking to qrng.anu.edu.au\n"; + return (); + } + + $response = $response->content(); + + # There isn't a quota or I haven't reached it yet, + # so I won't write code to handle it. + + grep { !/^$/ } + map { map { hex } $1 =~ /(..)/g if /([0-9a-f]{2048})/ } + split /\n/, $response; + } }, ); # recharges the randomness pool @@ -150,7 +171,7 @@ sub new { $_ !~ /^(src|min|max|ssl)$/ } keys %params) || !exists($params{src}) || - $params{src} !~ /^(fourmilab\.ch|random\.org)$/ || + $params{src} !~ /^(fourmilab\.ch|random\.org|qrng\.anu\.edu\.au)$/ || $params{min} !~ /^-?\d+$/ || $params{max} !~ /^-?\d+$/ || # $params{min} < 0 || diff --git a/t/fake-tests.t b/t/fake-tests.t index c0a2927..40dd59e 100644 --- a/t/fake-tests.t +++ b/t/fake-tests.t @@ -11,7 +11,7 @@ BEGIN { }; } -use Test::More tests => 17; +use Test::More tests => 20; use Test::MockObject; use Data::Dumper; @@ -58,11 +58,32 @@ $rand->get(); ok(!@statuses && $warning =~ /^Net::Random: random.org/, "random.org rationing detected OK"); +$rand = Net::Random->new(ssl => 0, src => 'qrng.anu.edu.au'); + +# Errors talking to qrng.anu.edu.au +$warning = ''; @statuses = (0); @content = (); +$rand->get(); +ok($warning =~ /^Net::Random: Error talking to qrng\.anu\.edu\.au/, + "error talking to qrng.anu.edu.au detected OK"); + # shouldn't ever get any more warnings, so make 'em all fatal $SIG{__WARN__} = sub { die("Caught a warning, making it fatal:\n", join('', @_)); }; +# grab real data from qrng.anu.edu.au +open(FILE, 't/qrng.anu.edu.au-data') || die ("Can't open t/qrng.anu.edu.au-data\n"); +$warning = ''; @statuses = (1); @content = (join('', <FILE>)); +close(FILE); +is_deeply([$rand->get()], [0x60], "we can get data from qrng.anu.edu.au"); +is_deeply( + [$rand->get(15)], + [0x6a,0x2c,0xd8,0x77,0x91,0x85,0xa0,0x49,0x59,0x9f,0x8d,0x65,0xd9,0x7d,0xc1], + "everything went ok" +); + +$rand = Net::Random->new(ssl => 0, src => 'random.org'); + # now grab some real data from random.org open(FILE, 't/random.org-data') || die("Can't open t/random.org-data\n"); $warning = ''; @statuses = (1); @content = (join('', <FILE>)); diff --git a/t/qrng.anu.edu.au-data b/t/qrng.anu.edu.au-data new file mode 100644 index 0000000..2040b10 --- /dev/null +++ b/t/qrng.anu.edu.au-data @@ -0,0 +1,104 @@ +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml"> +<head> +<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> +<meta http-equiv="cache-control" content="no-cache" /> +<meta http-equiv="cache-control" content="no-store" /> +<meta name="Keywords" content="quantum,random,number,generator,ANU,QRNG" /> +<meta name="Description" content="This is the ANU online Quantum Random Number Generator." /> +<title>ANU Quantum Random Number Server</title> +<script src="/SpryAssets/SpryMenuBar.js" type="text/javascript"></script> +<link href="/SpryAssets/SpryMenuBarHorizontal.css" rel="stylesheet" type="text/css" /> +<link rel="stylesheet" href="/rnstyle.css" type="text/css"/> + +<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.0/jquery.min.js"></script> +</head> + + +<body> +<div class="container"> +<div class="nav"> +<ul id="Navigation" class="MenuBarHorizontal"> +<li><a href="http://qrng.anu.edu.au/index.php" class="MenuBarItemSubMenu">Welcome</a> </li> +<li><a href="#" class="MenuBarItemSubmenu">Live Numbers</a> +<ul> +<li><a href="#" class="MenuBarItemSubmenu">Live streams</a> +<ul> +<li><a href="https://qrng.anu.edu.au/RainHex.php">Hex</a></li> +<li><a href="https://qrng.anu.edu.au/RainBin.php">Binary</a></li> +<li><a href="https://qrng.anu.edu.au/RainCol.php">Colours</a></li> +</ul> +</li> +<li><a href="#" class="MenuBarItemSubmenu">Blocks</a> +<ul> +<li><a href="https://qrng.anu.edu.au/RawChar.php">Char</a></li> +<li><a href="https://qrng.anu.edu.au/RawBin.php">Binary</a></li> +<li><a href="https://qrng.anu.edu.au/RawHex.php">Hex</a></li> +</ul> +</li> +<li><a href="#" class="MenuBarItemSubmenu">Fun Stuffs</a> +<ul> +<li><a href="http://qrng.anu.edu.au/Lucky.php">Dice Throw</a></li> +<li><a href="http://qrng.anu.edu.au/Perm.php">Permutations</a></li> +<li><a href="http://qrng.anu.edu.au/psychic/psychic.php">Quantum Guess</a></li> +<li><a href="http://qrng.anu.edu.au/Matrix.php">The Matrix</a></li> +</ul> +</li> +<li><a href="#" class="MenuBarItemSubmenu">Sensing Randomness</a> +<ul> +<li><a href="http://qrng.anu.edu.au/bingo/bingo.php">Bingo</a></li> +<li><a href="http://qrng.anu.edu.au/rnImg.php">B/W Pixels</a></li> +<li><a href="http://qrng.anu.edu.au/rnScatter.php">Scatter Plot</a></li> +<li><a href="http://qrng.anu.edu.au/rnLag.php">Lag Plot</a></li> +<li><a href="http://qrng.anu.edu.au/rnBern.php">Bernoulli Noise</a></li> +<li><a href="http://qrng.anu.edu.au/rnWN.php">White Noise</a></li> +</ul> +</li> +</ul> +</li> +<li><a href="#" class="MenuBarItemSubmenu">Randomness tests</a> +<ul> +<li><a href="http://qrng.anu.edu.au/NIST.php">NIST STS</a></li> +<li><a href="http://qrng.anu.edu.au/Diehard.php">Diehard</a></li> +<li><a href="http://qrng.anu.edu.au/Dieharder.php">Dieharder</a></li> +<li><a href="http://qrng.anu.edu.au/Birthday.php">Birthday Collision</a></li> +<li><a href="http://qrng.anu.edu.au/Dice.php">Dice Probabilities</a></li> +</ul> +</li> +<li><a href="#" class="MenuBarItemSubmenu">About</a> +<ul> +<li><a href="http://qrng.anu.edu.au/FAQ.php">FAQ</a></li> +<li><a href="http://qrng.anu.edu.au/Links.php">Links</a></li> +</ul> +</li> +<li><a href="http://qrng.anu.edu.au/About.php">Contact</a></li> +</ul> +</div> + +<script type="text/javascript"> +<!-- + var MenuBar1 = new Spry.Widget.MenuBar("Navigation", {imgDown:"/SpryAssets/SpryMenuBarDownHover.gif", imgRight:"/SpryAssets/SpryMenuBarRightHover.gif"}); + //--> + </script> + + +<div class="content"> + + +1024 bytes of randomness in hexadecimal form.<br /><br /> + + + +<table class="rng" cellpadding="10"> +<tr> +<td> +606a2cd8779185a049599f8d65d97dc11e69b7c4b9ef0d308b858e554b419cceff0f84d59b3b2dbbf740abf3ecdb725e44d99847e9e279206d26e4bc0fef8262a9d2e8ef06126dab3b88c5a8a7dcc79b314bd73f31414156487d1c7ee8768a5aa5655fc911b9c9d3821964055bdb8805a975d22367ac83f8c8783ef2f96c13842c4725bbb9d53bf4ccf3230143af6884a963bd54a4e32ac0ac9ab0dbe553991821385d4f79d7e903f1186812d4d9fd4c291458d912301c684657d739676de7bbe0ae44ed935c9cd1baac124a7262b6b3435367cd40212090c926d118e360c4ae9569c03531f516b4ebba40da89fe42aca1a8ec04c133367de208c2c0bcd54cf3e6f1f548b5aed6e070c914a626c77aa8e04d20fea39681f7c468940cfbaf941f00ac122e350ca162c9c8caec21f1af08d9520e5abe841fb4a50ba12d0f761f46d2438a2aceb96aa04772df1c1d4c9d5a476d2cae9046a661a1cbfe40f9f0e4736e24416e175367a4f15f09b4de6ea75546ab873c4f5afd2f55f546dbbcdd1f7af164e93d2e92e6cc94a2f162c876884c3858c9c03cecd7febd885abb48cc26600ba3766e42ddea84c208e173b44f59ba09c118c030e9f2ad8234d3df0dba5bd5d6bdc8006cb9ee6fdcffd329a214855fbeeb64cde7688b7a3d529e83cf8b5ff15a98fb99dbccd07bc2679bd89ad5d89448fbf8a24e74565d7777f844aa4489e0d773b9fd536d96647693adc6d686175df0ce66fe4e1302aa54ee50494c897260f5ac8cce5333b9f831edd3aea349ed52520f28c0a18d655406bfbf36ff966e0535495738f49468ff8983c2dd5902dd2894d1e9635e60b5a3418b2619a04547b1e3e3d1cb267c316c87f4e8f98ba395606e6177be14eb7dd53a5a870c776a900c8247cb913b6612f8de246443fbc8dee5e7636176dfd900944f6999e7648a5c8c9323b0c704531633a46f9c7c090b76501498aee0ddd01dbf7625f648bd3a83ca5c3e83726a7015d32a573d2db45f8fbcd6f7a31c57ef215cdd6b2f4106be3232beaedec46fda9085cde872cb309e3e6c16b43bc73955f01eb43cd22d2e2bf4a593dd12aee4605e091f7b510fe14c83af4d6f0ca11bf9011d26507133ed97d3a03ce57122a5ca52a15acdad4f5aa9ca298a704ec5471f032d9d8ebde0cbcb9f0e50573edc746b2186e678ac3029345bb91fe9a07a3ca83ab5f2317ed29d0889a37b5663c5071e4174206d9f3ce3a473bc8176285ec628fd7e224e7010e750f7adc9518d8aad2b4e49af8c3dfec104d244d79ec2df7b55cabe91febfb3118d8f94570f5d04ca63fe899c5a9227c44898452537fbc92192a1b4818454cd495b2523070b05a5a66c131ce213c72685e5b8e4de4e82bcf32685b65eeae0b67f022a92daa36b8a804c3333727c69feef32b8e7f4d4e3bbf2363a74cae2898e1633b6c3</td> +</tr> +</table> + +<br /> + + <!-- end .content --></div> + <!-- end .container --></div> +</body> +</html> \ No newline at end of file
Duplicate of ticket raised (and patch applied) on github