[system] / trunk / pg / lib / PGrandom.pm Repository:
ViewVC logotype

Diff of /trunk/pg/lib/PGrandom.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 1050 Revision 1079
1#! /usr/math/bin/perl -w 1
2 2
3 3
4package PGrandom; 4package PGrandom;
5 5
6 6
21 $seed = mod ($multiplier * $seed + $translate, $modulus); 21 $seed = mod ($multiplier * $seed + $translate, $modulus);
22 my $self = { 'seed' => $seed, 22 my $self = { 'seed' => $seed,
23 'original_seed' => $original_seed, # this and the next value are largely for debugging 23 'original_seed' => $original_seed, # this and the next value are largely for debugging
24 'number_of_calls' => 1 # there is always one call to set the seed. 24 'number_of_calls' => 1 # there is always one call to set the seed.
25 }; 25 };
26 26
27 bless $self, $class; 27 bless $self, $class;
28 28
29 return $self; 29 return $self;
30} 30}
31sub mod { # for some reason perl's % doesn't seem to work for large numbers? 31sub mod { # for some reason perl's % doesn't seem to work for large numbers?
32 my $a = shift; 32 my $a = shift;
33 my $b = shift; 33 my $b = shift;
49 $out = $begin +$incr*int( ($new_seed/($modulus))*( ($end-$begin)/$incr +1 ) ) ; 49 $out = $begin +$incr*int( ($new_seed/($modulus))*( ($end-$begin)/$incr +1 ) ) ;
50 } else { # if $incr is less than zero return "continuous" distribution 50 } else { # if $incr is less than zero return "continuous" distribution
51 $out = $begin + ($end-$begin)*$new_seed/$modulus; 51 $out = $begin + ($end-$begin)*$new_seed/$modulus;
52 } 52 }
53 $out; 53 $out;
54 54
55} 55}
56sub rand { 56sub rand {
57 my $self = shift; 57 my $self = shift;
58 my $end = shift; 58 my $end = shift;
59 $end = 1 unless defined($end); 59 $end = 1 unless defined($end);

Legend:
Removed from v.1050  
changed lines
  Added in v.1079

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9