Pseudo-random numbers/Combined recursive generator MRG32k3a: Difference between revisions
Content added Content deleted
Thundergnat (talk | contribs) m (→{{header|Raku}}: eliminate some intermediates, slightly more efficient) |
Thundergnat (talk | contribs) m (→{{header|Raku}}: minor style tweaks) |
||
Line 141: | Line 141: | ||
constant m2 = 2**32 - 22853; |
constant m2 = 2**32 - 22853; |
||
submethod BUILD ( Int :$seed where |
submethod BUILD ( Int :$seed where 0 < * < m1 + 1 = 1 ) { @!x1 = @!x2 = $seed, 0, 0 } |
||
method next-int { |
method next-int { |
||
Line 155: | Line 155: | ||
# Test next-int with custom seed |
# Test next-int with custom seed |
||
say 'Seed: 1234567; first five Int values:'; |
say 'Seed: 1234567; first five Int values:'; |
||
my $rng = MRG32k3a.new |
my $rng = MRG32k3a.new :seed(1234567); |
||
.say for $rng.next-int xx 5; |
.say for $rng.next-int xx 5; |
||
Line 161: | Line 161: | ||
# Test next-rat (since these are rational numbers by default) |
# Test next-rat (since these are rational numbers by default) |
||
say "\nSeed: 987654321; first 1e5 Rat values histogram:"; |
say "\nSeed: 987654321; first 1e5 Rat values histogram:"; |
||
$rng = MRG32k3a.new |
$rng = MRG32k3a.new :seed(987654321); |
||
say ( ($rng.next-rat * 5).floor xx 100_000 ).Bag; |
say ( ($rng.next-rat * 5).floor xx 100_000 ).Bag; |
||
Line 185: | Line 185: | ||
1012402089 |
1012402089 |
||
1268414425 |
1268414425 |
||
3353586348 |
3353586348</pre> |
||
</pre> |