Here's a P-RNG that I have to work well.
--njg
#! /usr/bin/perl -w
#
# yapr.pl - Yet another portable RNG
#
# Created by NJG 09:14:16 AM Thu, Feb 20, 2003
sub rand_val {
use integer;
use constant ac => 16807; # Multiplier
use constant mc => 2147483647; # Modulus
use constant qc => 127773; # m div a
use constant rc => 2836; # m mod a
my $x_div_q; # x divided by q
my $x_mod_q; # x modulo q
my $x_new; # New x value
# RNG using integer arithmetic
$x_div_q = $x / qc;
$x_mod_q = $x % qc;
$x_new = (ac * $x_mod_q) - (rc * $x_div_q);
if ($x_new > 0) {
$x = $x_new;
}
else {
$x = $x_new + mc;
}
# Return a random value between 0.0 and 1.0
no integer;
return($x / mc);
}
sub test_rv {
$x = 1; # set seed value to 1
for ($i = 0; $i < 10000; $i++) {$rv = rand_val();}
print "Thousandth iterate should be 1043618065: $x\n";
print "Thousandth random variate: $rv\n";
print "\n";
}
test_rv();
___________________________________________________________________________
PERFORMANCE DYNAMICS COMPANY(sm) http://www.perfdynamics.com/
___________________________________________________________________________
Consulting Services Educational Services
4061 East Castro Valley Blvd. P.O. Box 1238, Magalia
Suite 110, Castro Valley California 95954, USA
California 94552, USA Bookings and registrations
FON: +1-510-537-5758 FON: +1-530-873-0575
FAX: Dial FON (Handshakes automagically) FAX: +1-530-873-6697
NET: [EMAIL PROTECTED] NET: [EMAIL PROTECTED]
___________________________________________________________________________