in reply to Re^4: rand() function on Windows systems (pure Perl)
in thread rand() function on Windows systems
Hm. I forgot that Perl would upgrade the seed to a float; that needs to be clamped back to a 32-bit integer as the new line below:
{ my $seed; sub ppSrand{ $seed = int( $_[ 0 ] & 32767 ); } sub ppRand{ my $max = shift // 1; $seed = ( $seed * 214013 + 2531011 ); $seed &= 0xffffffff; return ( ( $seed >> 16 ) & 32767 ) / 32768 * $max; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^6: rand() function on Windows systems (pure Perl)(Correction)
by bakiperl (Beadle) on Jan 01, 2017 at 23:09 UTC |