$MAX = 1024; ## the largest random value, and the length of ## our RNG's period. you can use any power ## of two if you want a larger (or smaller) ## period. $A = 5; ## $A should be relatively prime to $MAX, and ## ($A-1) should be divisible by 4 if $MAX is ## divisible by 4 (it is). $C = 113; ## $C must be relatively prime to $MAX, and ## 113 is prime, full stop. $SEED = 42; ## just a starting value, and all good ## _Hitchhiker's Guide_ fans love 42. sub lcrng { if ( ! defined $CURRENT ) { $CURRENT = $SEED; } $CURRENT = (($CURRENT * $A) + $C) % $MAX; return ($CURRENT / $MAX); } ## and some test code for $i (1..1032) { printf "%5.3f ", lcrng(); print "\n" if (0 == $i % 8); }