r3779 - in /packages/libmath-randomorg-perl: ./ branches/ branches/upstream/ branches/upstream/current/ branches/upstream/current/lib/ branches/upstream/current/lib/Math/ branches/upstream/current/t/ tags/

gregoa-guest at users.alioth.debian.org gregoa-guest at users.alioth.debian.org
Thu Sep 14 22:19:32 UTC 2006


Author: gregoa-guest
Date: Thu Sep 14 22:19:31 2006
New Revision: 3779

URL: http://svn.debian.org/wsvn/pkg-perl/?sc=1&rev=3779
Log:
[svn-inject] Installing original source of libmath-randomorg-perl

Added:
    packages/libmath-randomorg-perl/
    packages/libmath-randomorg-perl/branches/
    packages/libmath-randomorg-perl/branches/upstream/
    packages/libmath-randomorg-perl/branches/upstream/current/
    packages/libmath-randomorg-perl/branches/upstream/current/Changes
    packages/libmath-randomorg-perl/branches/upstream/current/MANIFEST
    packages/libmath-randomorg-perl/branches/upstream/current/MANIFEST.SKIP
    packages/libmath-randomorg-perl/branches/upstream/current/META.yml
    packages/libmath-randomorg-perl/branches/upstream/current/Makefile.PL
    packages/libmath-randomorg-perl/branches/upstream/current/README
    packages/libmath-randomorg-perl/branches/upstream/current/lib/
    packages/libmath-randomorg-perl/branches/upstream/current/lib/Math/
    packages/libmath-randomorg-perl/branches/upstream/current/lib/Math/RandomOrg.pm
    packages/libmath-randomorg-perl/branches/upstream/current/t/
    packages/libmath-randomorg-perl/branches/upstream/current/t/randbyte.t
    packages/libmath-randomorg-perl/branches/upstream/current/t/randnum.t
    packages/libmath-randomorg-perl/tags/

Added: packages/libmath-randomorg-perl/branches/upstream/current/Changes
URL: http://svn.debian.org/wsvn/pkg-perl/packages/libmath-randomorg-perl/branches/upstream/current/Changes?rev=3779&op=file
==============================================================================
--- packages/libmath-randomorg-perl/branches/upstream/current/Changes (added)
+++ packages/libmath-randomorg-perl/branches/upstream/current/Changes Thu Sep 14 22:19:31 2006
@@ -1,0 +1,12 @@
+Revision history for Perl extension Math/RandomOrg.pm:
+
+0.03	Tue May 30  02:56:00 EST 2006
+	- Added checkbuf() and randseq() functions (thanks to Aaron Dalton).
+
+0.02	Wed Jan 9  06:50:00 EST 2002
+	- fixed POD syntax error
+	- cleaned up for CPAN release
+
+0.01	Tue Oct 16 16:34:00 EST 2001
+	- original version 
+

Added: packages/libmath-randomorg-perl/branches/upstream/current/MANIFEST
URL: http://svn.debian.org/wsvn/pkg-perl/packages/libmath-randomorg-perl/branches/upstream/current/MANIFEST?rev=3779&op=file
==============================================================================
--- packages/libmath-randomorg-perl/branches/upstream/current/MANIFEST (added)
+++ packages/libmath-randomorg-perl/branches/upstream/current/MANIFEST Thu Sep 14 22:19:31 2006
@@ -1,0 +1,9 @@
+Changes
+lib/Math/RandomOrg.pm
+Makefile.PL
+MANIFEST
+MANIFEST.SKIP
+README
+t/randbyte.t
+t/randnum.t
+META.yml                                 Module meta-data (added by MakeMaker)

Added: packages/libmath-randomorg-perl/branches/upstream/current/MANIFEST.SKIP
URL: http://svn.debian.org/wsvn/pkg-perl/packages/libmath-randomorg-perl/branches/upstream/current/MANIFEST.SKIP?rev=3779&op=file
==============================================================================
--- packages/libmath-randomorg-perl/branches/upstream/current/MANIFEST.SKIP (added)
+++ packages/libmath-randomorg-perl/branches/upstream/current/MANIFEST.SKIP Thu Sep 14 22:19:31 2006
@@ -1,0 +1,14 @@
+\.AppleDouble/.*
+CVS/.*
+\.bak$
+\.sw[a-z]$
+\.tar$
+\.tgz$
+\.tar\.gz$
+^mess/
+^tmp/
+^Tblib/
+^Makefile$
+^Makefile\.[a-z]+$
+^pm_to_blib$
+~$

Added: packages/libmath-randomorg-perl/branches/upstream/current/META.yml
URL: http://svn.debian.org/wsvn/pkg-perl/packages/libmath-randomorg-perl/branches/upstream/current/META.yml?rev=3779&op=file
==============================================================================
--- packages/libmath-randomorg-perl/branches/upstream/current/META.yml (added)
+++ packages/libmath-randomorg-perl/branches/upstream/current/META.yml Thu Sep 14 22:19:31 2006
@@ -1,0 +1,11 @@
+# http://module-build.sourceforge.net/META-spec.html
+#XXXXXXX This is a prototype!!!  It will change in the future!!! XXXXX#
+name:         Math-RandomOrg
+version:      0.03
+version_from: lib/Math/RandomOrg.pm
+installdirs:  site
+requires:
+    LWP:                           0
+
+distribution_type: module
+generated_by: ExtUtils::MakeMaker version 6.17

Added: packages/libmath-randomorg-perl/branches/upstream/current/Makefile.PL
URL: http://svn.debian.org/wsvn/pkg-perl/packages/libmath-randomorg-perl/branches/upstream/current/Makefile.PL?rev=3779&op=file
==============================================================================
--- packages/libmath-randomorg-perl/branches/upstream/current/Makefile.PL (added)
+++ packages/libmath-randomorg-perl/branches/upstream/current/Makefile.PL Thu Sep 14 22:19:31 2006
@@ -1,0 +1,9 @@
+use ExtUtils::MakeMaker;
+
+WriteMakefile(
+    'NAME'		=> 'Math::RandomOrg',
+    'AUTHOR'	=> 'Gregory Todd Williams <gwilliams at cpan.org>',
+    'ABSTRACT_FROM'	=> 'lib/Math/RandomOrg.pm', # finds ABSTRACT
+    'VERSION_FROM'	=> 'lib/Math/RandomOrg.pm', # finds $VERSION
+    'PREREQ_PM'		=> { LWP => 0 }
+);

Added: packages/libmath-randomorg-perl/branches/upstream/current/README
URL: http://svn.debian.org/wsvn/pkg-perl/packages/libmath-randomorg-perl/branches/upstream/current/README?rev=3779&op=file
==============================================================================
--- packages/libmath-randomorg-perl/branches/upstream/current/README (added)
+++ packages/libmath-randomorg-perl/branches/upstream/current/README Thu Sep 14 22:19:31 2006
@@ -1,0 +1,43 @@
+==============================================================================
+                 Release of version 0.02 of Math::RandomOrg
+==============================================================================
+
+
+NAME
+
+    Math::RandomOrg - Retrieve random numbers and data from random.org.
+
+
+DESCRIPTION
+
+    Math::RandomOrg provides functions for retrieving random data from
+    the random.org server. Data may be retrieved in an integer or byte
+    stream format using the C<randnum> and C<randbyte> functions
+    respectively.
+
+REQUIRES
+
+    Carp
+    LWP::Simple
+    Math::BigInt
+
+INSTALLING
+
+    To install, run the following commands:
+    
+      perl Makefile.PL
+      make
+      make test
+      make install
+
+AUTHOR
+
+    Gregory Todd Williams <gwilliams at cpan.org>
+
+
+COPYRIGHT
+
+	 Copyright (c) 2001--2006, Gregory Williams. All rights reserved.
+	 This module is free software. It may be used, redistributed
+	 and/or modified under the same terms as Perl itself.
+

Added: packages/libmath-randomorg-perl/branches/upstream/current/lib/Math/RandomOrg.pm
URL: http://svn.debian.org/wsvn/pkg-perl/packages/libmath-randomorg-perl/branches/upstream/current/lib/Math/RandomOrg.pm?rev=3779&op=file
==============================================================================
--- packages/libmath-randomorg-perl/branches/upstream/current/lib/Math/RandomOrg.pm (added)
+++ packages/libmath-randomorg-perl/branches/upstream/current/lib/Math/RandomOrg.pm Thu Sep 14 22:19:31 2006
@@ -1,0 +1,228 @@
+=head1 NAME
+
+Math::RandomOrg - Retrieve random numbers and data from random.org.
+
+=head1 SYNOPSIS
+
+  use Math::RandomOrg qw(randnum randbyte);
+  my $number = randnum(0, 10);
+  my $octet = randbyte(1);
+
+=head1 DESCRIPTION
+
+Math::RandomOrg provides functions for retrieving random data from the random.org server. Data may be retrieved in an integer or byte-stream format using the C<randnum> and C<randbyte> functions respectively.
+
+=head1 REQUIRES
+
+=over 4
+
+=item Carp
+
+=item Exporter
+
+=item Math::BigInt
+
+=item LWP::Simple
+
+=back
+
+=head1 EXPORT
+
+None by default. You may request the following symbols be exported:
+
+=over 4
+
+=item * randnum
+
+=item * randbyte
+
+=back
+
+=cut
+
+package Math::RandomOrg;
+
+use strict;
+use vars qw(@ISA @EXPORT_OK @EXPORT $VERSION);
+
+require Exporter;
+
+ at ISA = qw(Exporter);
+
+ at EXPORT_OK = qw( checkbuf randnum randbyte randseq );
+ at EXPORT = qw();
+$VERSION = '0.03';
+
+use Carp;
+use Math::BigInt;
+use LWP::Simple ();
+
+my $RAND_MIN	= new Math::BigInt "-1000000000";	# random.org fixed min
+my $RAND_MAX	= new Math::BigInt "1000000000";	# random.org fixed max
+my $NUM_BUF	= 256;									# at least, request this number of random integers in each request to random.org
+
+=head1 FUNCTIONS
+
+=over 4
+
+=cut
+
+{
+	my @randnums;
+
+=item C<checkbuf()>
+
+This routine takes no parameters and simply returns a single value (e.g., 
+C<28%>) telling you how full the buffer is. At 100%, the buffer is full 
+and you are free to hit it with automated clients. At 0%, the buffer is 
+empty and requests will hang. When less than 100%, the buffer is being 
+filled continually, but doing so takes time. I advise people with 
+automated clients to check the buffer level every once in a while and only 
+issue requests when the buffer level is 20% or higher.
+
+=cut
+
+	sub checkbuf {
+		my $url		= "http://www.random.org/cgi-bin/checkbuf";
+		my $data	= LWP::Simple::get( $url );
+		if (defined($data)) {
+			$data =~ s/\%//;
+			return $data;
+		} else {
+			carp "HTTP GET failed for $url";
+			return;
+		}
+	}
+
+=item C<randnum ( $min, $max )>
+
+Return an integer (specifically a Math::BigInt object) between the bounds [ $min, $max ] (inclusive).
+
+By default, $max and $min are positive and negative 1e9, respectively. These default
+values represent random.org's current extrema for the bounds of the randnum function.
+Therefore, $min and $max may not exceed the default values.
+
+=cut
+	sub randnum (;$$) {
+		use integer;
+		my $min	= new Math::BigInt (defined($_[0]) ? $_[0] : $RAND_MIN);
+		my $max	= new Math::BigInt (defined($_[1]) ? $_[1] : $RAND_MAX);
+		if ($min < $RAND_MIN or $max > $RAND_MAX) {
+			carp "The $min and $max arguments to the randnum() function may not exceed the bounds ($RAND_MIN, $RAND_MAX)!";
+			return undef;
+		}
+		if ($#randnums == -1) {
+			my $url		= "http://www.random.org/cgi-bin/randnum?num=${NUM_BUF}&min=${RAND_MIN}&max=${RAND_MAX}&col=1";
+			my $data	= LWP::Simple::get( $url );
+			if (defined($data)) {
+				@randnums	= map { new Math::BigInt $_ } (split(/\n/, $data));
+			} else {
+				carp "HTTP GET failed for $url";
+				return undef;
+			}
+		}
+		my $num	= shift(@randnums);
+		
+		$num	-= $RAND_MIN;
+		$num	*= (1 + $max - $min);
+		$num	/= ($RAND_MAX - $RAND_MIN);
+		$num	+= $min;
+		
+		return $num;
+	}
+
+	my $randbytes	= '';
+
+=item C<randbyte ( $length )>
+
+Returns an octet-string of specified length (defaults to one byte), which contains random bytes.
+
+$length may not exceed 16,384, as this is the maximum number of bytes retrievable from the
+random.org server in one request, and making multiple requests for an unbounded amount of
+data would unfairly tax the random.org server. If you need large amounts of random data,
+you may wish to try the Math::TrulyRandom module.
+
+=cut
+	sub randbyte (;$) {
+		my $length	= +(shift || 1);
+		if ($length > 16_384) {
+			carp "randbyte() should not be used to generate random data larger than 16,384 bytes (lest we swamp random.org's entropy source).";
+			return '';
+		} elsif (length($randbytes) < $length) {
+			my $nbytes	= ($length > 512) ? $length : 512;
+			my $url		= "http://www.random.org/cgi-bin/randbyte?nbytes=${nbytes}&format=f";
+			my $data	= LWP::Simple::get( $url );
+			if (defined($data)) {
+				$randbytes	.= $data;
+			} else {
+				carp "HTTP GET failed for $url";
+				return undef;
+			}
+		}
+		return substr($randbytes, 0, $length, '');
+	}
+}
+
+=item C<randseq ( $min, $max )>
+
+The randseq script returns a randomized sequence of numbers. This corresponds to dropping a number of lottery tickets into a hat and drawing them out in random order. Hence, each number in a randomized sequence occurs exactly once.
+
+Example: C<randseq(1, 10)> will return the numbers between 1 and 10 (both inclusive) in a random order.
+
+=cut
+
+	sub randseq (;$$) {
+		my ($min, $max) = @_;
+		return if ( (! defined $min) || (! defined $max) || ($min !~ /^\-?\d+$/) || ($max !~ /^\-?\d+$/) );
+		if ($max < $min) {
+			carp "MAX must be greater than MIN.";
+			return;
+		}
+		if ($max - $min > 10000) {
+			carp "random.org restricts the size of sequences to <= 10,000.";
+			return;
+		}
+		my @sequence = ();
+		my $url		= "http://www.random.org/cgi-bin/randseq?min=$min&max=$max";
+		my $data	= LWP::Simple::get( $url );
+		if (defined($data)) {
+			@sequence = map { new Math::BigInt $_ } (split(/\n/, $data));
+		} else {
+			carp "HTTP GET failed for $url";
+			return undef;
+		}
+		
+		return wantarray ? @sequence : \@sequence;
+	}
+
+1;
+__END__
+
+=back
+
+=head1 BUGS
+
+None known.
+
+=head1 AUTHOR
+
+Gregory Williams <gwilliams at cpan.org>
+
+=head1 SEE ALSO
+
+=over 4
+
+=item * L<Math::TrulyRandom>
+
+=item * L<rand>
+
+=back
+
+=head1 COPYRIGHT
+
+Copyright (c) 2001--2006, Gregory Williams. All rights reserved.
+This module is free software. It may be used, redistributed
+and/or modified under the same terms as Perl itself.
+
+=cut
+

Added: packages/libmath-randomorg-perl/branches/upstream/current/t/randbyte.t
URL: http://svn.debian.org/wsvn/pkg-perl/packages/libmath-randomorg-perl/branches/upstream/current/t/randbyte.t?rev=3779&op=file
==============================================================================
--- packages/libmath-randomorg-perl/branches/upstream/current/t/randbyte.t (added)
+++ packages/libmath-randomorg-perl/branches/upstream/current/t/randbyte.t Thu Sep 14 22:19:31 2006
@@ -1,0 +1,13 @@
+use strict;
+use Test;
+use Math::RandomOrg qw(randnum randbyte);
+
+BEGIN {
+	plan tests => (10)
+}
+
+for my $i (1 .. 10) {
+	my $octets	= randbyte( $i );
+	ok( length($octets), $i );
+}
+

Added: packages/libmath-randomorg-perl/branches/upstream/current/t/randnum.t
URL: http://svn.debian.org/wsvn/pkg-perl/packages/libmath-randomorg-perl/branches/upstream/current/t/randnum.t?rev=3779&op=file
==============================================================================
--- packages/libmath-randomorg-perl/branches/upstream/current/t/randnum.t (added)
+++ packages/libmath-randomorg-perl/branches/upstream/current/t/randnum.t Thu Sep 14 22:19:31 2006
@@ -1,0 +1,17 @@
+use strict;
+use Test;
+use Math::RandomOrg qw(randnum randbyte);
+
+BEGIN {
+	plan tests => (3*3*20)
+}
+
+foreach my $max (1, 1_000, 1_000_000_000) {
+	foreach my $min (1, 0, -1_000_000_000) {
+		for (1 .. 20) {
+			my $number	= randnum( $min, $max );
+			($number >= $min and $number <= $max) ? ok(1) : ok(0);
+		}
+	}
+}
+




More information about the Pkg-perl-cvs-commits mailing list