Pseudo-random numbers/Splitmix64: Difference between revisions
Content added Content deleted
m (→{{header|Factor}}: use 2^ instead of ^) |
Thundergnat (talk | contribs) (Doh. Confidently incorrect. Fix some precedence / bit masking problems. Replace wrong expected results with correct ones.) |
||
Line 34: | Line 34: | ||
* Show the first five integers generated using the seed 1234567. |
* Show the first five integers generated using the seed 1234567. |
||
6457827717110365317 |
|||
3203168211198807973 |
|||
12075168200337577354 |
|||
9817491932198370423 |
|||
4593380528125082431 |
|||
10975871416297420776 |
|||
16408922859458223821 |
|||
2494458855142162015 |
|||
* Show that for an initial seed of 987654321, the counts of 100_000 repetitions of <code>floor next_float() * 5</code> is as follows: |
* Show that for an initial seed of 987654321, the counts of 100_000 repetitions of <code>floor next_float() * 5</code> is as follows: |
||
0: |
0: 20027, 1: 19892, 2: 20073, 3: 19978, 4: 20030 |
||
* Show your output here, on this page. |
* Show your output here, on this page. |
||
Line 59: | Line 60: | ||
;* [[Pseudo-random numbers/PCG32]] |
;* [[Pseudo-random numbers/PCG32]] |
||
;* [[Pseudo-random_numbers/Xorshift_star]] |
;* [[Pseudo-random_numbers/Xorshift_star]] |
||
=={{header|C}}== |
=={{header|C}}== |
||
Line 222: | Line 225: | ||
method next-int { |
method next-int { |
||
my $next = $!state |
my $next = $!state = ($!state + 0x9e3779b97f4a7c15) +& (2⁶⁴ - 1); |
||
$next +^ |
$next = ($next +^ ($next +> 30)) * 0xbf58476d1ce4e5b9 +& (2⁶⁴ - 1); |
||
$next +^ |
$next = ($next +^ ($next +> 27)) * 0x94d049bb133111eb +& (2⁶⁴ - 1); |
||
($next +^ |
($next +^ ($next +> 31)) +& (2⁶⁴ - 1); |
||
} |
} |
||
Line 243: | Line 246: | ||
{{out}} |
{{out}} |
||
<pre>Seed: 1234567; first five Int values |
<pre>Seed: 1234567; first five Int values |
||
6457827717110365317 |
|||
9086773575395155592 |
|||
3203168211198807973 |
|||
12075168200337577354 |
|||
9817491932198370423 |
|||
5360881288835356517 |
|||
4593380528125082431 |
|||
10975871416297420776 |
|||
16408922859458223821 |
|||
2494458855142162015 |
|||
Seed: 987654321; first 1e5 Rat values histogram |
Seed: 987654321; first 1e5 Rat values histogram |
||
Bag(0( |
Bag(0(20027) 1(19892) 2(20073) 3(19978) 4(20030))</pre> |
||
=={{header|Wren}}== |
=={{header|Wren}}== |