Pseudo-random numbers/Splitmix64: Difference between revisions
Content added Content deleted
(Added Forth entry) |
Alextretyak (talk | contribs) (Added 11l) |
||
Line 62: | Line 62: | ||
=={{header|11l}}== |
|||
{{trans|Python}} |
|||
<lang 11l>T Splitmix64 |
|||
UInt64 state |
|||
F seed(seed_state) |
|||
.state = seed_state |
|||
F next_int() |
|||
.state += 9E37'79B9'7F4A'7C15 |
|||
V z = .state |
|||
z = (z (+) (z >> 30)) * BF58'476D'1CE4'E5B9 |
|||
z = (z (+) (z >> 27)) * 94D0'49BB'1331'11EB |
|||
R z (+) (z >> 31) |
|||
F next_float() |
|||
R Float(.next_int()) / 2.0^64 |
|||
V random_gen = Splitmix64() |
|||
random_gen.seed(1234567) |
|||
L 5 |
|||
print(random_gen.next_int()) |
|||
random_gen.seed(987654321) |
|||
V hist = Dict(0.<5, i -> (i, 0)) |
|||
L(i) 100'000 |
|||
hist[Int(random_gen.next_float() * 5)]++ |
|||
print(hist)</lang> |
|||
{{out}} |
|||
<pre> |
|||
6457827717110365317 |
|||
3203168211198807973 |
|||
9817491932198370423 |
|||
4593380528125082431 |
|||
16408922859458223821 |
|||
[0 = 20027, 1 = 19892, 2 = 20073, 3 = 19978, 4 = 20030] |
|||
</pre> |
|||
=={{header|ALGOL 68}}== |
=={{header|ALGOL 68}}== |