summaryrefslogtreecommitdiff
path: root/Master/tlpkg/tlperl0/lib/Crypt/Random/Provider/rand.pm
diff options
context:
space:
mode:
Diffstat (limited to 'Master/tlpkg/tlperl0/lib/Crypt/Random/Provider/rand.pm')
-rwxr-xr-xMaster/tlpkg/tlperl0/lib/Crypt/Random/Provider/rand.pm60
1 files changed, 60 insertions, 0 deletions
diff --git a/Master/tlpkg/tlperl0/lib/Crypt/Random/Provider/rand.pm b/Master/tlpkg/tlperl0/lib/Crypt/Random/Provider/rand.pm
new file mode 100755
index 00000000000..8f34f193f57
--- /dev/null
+++ b/Master/tlpkg/tlperl0/lib/Crypt/Random/Provider/rand.pm
@@ -0,0 +1,60 @@
+#!/usr/bin/perl -sw
+##
+## Crypt::Random::Provider::rand
+##
+## Copyright (c) 2001, Vipul Ved Prakash. All rights reserved.
+## This code is free software; you can redistribute it and/or modify
+## it under the same terms as Perl itself.
+##
+## $Id: rand.pm,v 1.2 2001/06/22 18:16:29 vipul Exp $
+
+package Crypt::Random::Provider::rand;
+use strict;
+use Math::Pari qw(pari2num);
+
+sub new {
+
+ my ($class, %params) = @_;
+ my $self = { Source => $params{Source} || sub { return rand($_[0]) } };
+ return bless $self, $class;
+
+}
+
+
+sub get_data {
+
+ my ($self, %params) = @_;
+ $self = {} unless ref $self;
+
+ my $size = $params{Size};
+ my $skip = $params{Skip} || $$self{Skip};
+
+ if ($size && ref $size eq "Math::Pari") {
+ $size = pari2num($size);
+ }
+
+ my $bytes = $params{Length} || (int($size / 8) + 1);
+ my $source = $$self{Source} || sub { rand($_[0]) };
+
+ my($r, $read, $rt) = ('', 0);
+ while ($read < $bytes) {
+ $rt = chr(int(&$source(256)));
+ unless ($skip && $skip =~ /\Q$rt\E/) {
+ $r .= $rt; $read++;
+ }
+ }
+
+ $r;
+
+}
+
+
+sub available {
+
+ return 1;
+
+}
+
+
+1;
+