| 16 | | my $max = $_[0] || 1; # if no value is passed, we return '0' or '1' |
|---|
| 17 | | use integer; # is it faster not to use integer? No, it's faster to USE int. |
|---|
| 18 | | $last = 1 unless defined($last); |
|---|
| 19 | | $last = ($last*21+1); |
|---|
| 20 | | # from "Advanced Perl Programming", 4.4 Using Closures. |
|---|
| 21 | | # We truncate to 30 bits to preclude system overflow and thereby be more portable |
|---|
| 22 | | # that would be 'mod 2 ** 30' (1,073,741,824), which makes sense, 4.2G over 4 |
|---|
| 23 | | $last %= 1_073_741_824; # that's 2 to the 30th |
|---|
| 24 | | #print "rand of $max is " . abs($last % $max) . "\n"; |
|---|
| 25 | | return abs($last % $max); # abs isn't needed |
|---|
| | 16 | my $max = $_[0] || 1; # if no value is passed, we return '0' or '1' |
|---|
| | 17 | use integer; # is it faster not to use integer? No, it's faster to USE int. |
|---|
| | 18 | $last = 1 unless defined($last); |
|---|
| | 19 | $last = ($last*21+1); |
|---|
| | 20 | # from "Advanced Perl Programming", 4.4 Using Closures. |
|---|
| | 21 | # We truncate to 30 bits to preclude system overflow and thereby be more portable |
|---|
| | 22 | # that would be 'mod 2 ** 30' (1,073,741,824), which makes sense, 4.2G over 4 |
|---|
| | 23 | $last %= 1_073_741_824; # that's 2 to the 30th |
|---|
| | 24 | #print "rand of $max is " . abs($last % $max) . "\n"; |
|---|
| | 25 | return abs($last % $max); # abs isn't needed |
|---|