Pseudo-random numbers/Combined recursive generator MRG32k3a: Difference between revisions
Content added Content deleted
No edit summary |
Alextretyak (talk | contribs) (Added 11l) |
||
Line 69: | Line 69: | ||
* Show your output here, on this page. |
* Show your output here, on this page. |
||
=={{header|11l}}== |
|||
{{trans|Python}} |
|||
<lang 11l>V a1 = [Int64(0), 1403580, -810728] |
|||
V m1 = Int64(2) ^ 32 - 209 |
|||
V a2 = [Int64(527612), 0, -1370589] |
|||
V m2 = Int64(2) ^ 32 - 22853 |
|||
V d = m1 + 1 |
|||
T MRG32k3a |
|||
[Int64] x1, x2 |
|||
F (seed_state = 123) |
|||
.seed(seed_state) |
|||
F seed(Int64 seed_state) |
|||
assert(seed_state C Int64(0) <.< :d, ‘Out of Range 0 x < #.’.format(:d)) |
|||
.x1 = [Int64(seed_state), 0, 0] |
|||
.x2 = [Int64(seed_state), 0, 0] |
|||
F next_int() |
|||
‘return random int in range 0..d’ |
|||
V x1i = (sum(zip(:a1, .x1).map((aa, xx) -> aa * xx)) % :m1 + :m1) % :m1 |
|||
V x2i = (sum(zip(:a2, .x2).map((aa, xx) -> aa * xx)) % :m2 + :m2) % :m2 |
|||
.x1 = [x1i] [+] .x1[0.<2] |
|||
.x2 = [x2i] [+] .x2[0.<2] |
|||
V z = ((x1i - x2i) % :m1 + :m1) % :m1 |
|||
R z + 1 |
|||
F next_float() |
|||
‘return random float between 0 and 1’ |
|||
R Float(.next_int()) / :d |
|||
V random_gen = MRG32k3a() |
|||
random_gen.seed(1234567) |
|||
L 5 |
|||
print(random_gen.next_int()) |
|||
random_gen.seed(987654321) |
|||
V hist = Dict(0.<5, i -> (i, 0)) |
|||
L 100'000 |
|||
hist[Int(random_gen.next_float() * 5)]++ |
|||
print(hist)</lang> |
|||
{{out}} |
|||
<pre> |
|||
1459213977 |
|||
2827710106 |
|||
4245671317 |
|||
3877608661 |
|||
2595287583 |
|||
[0 = 20002, 1 = 20060, 2 = 19948, 3 = 20059, 4 = 19931] |
|||
</pre> |
|||
=={{header|Ada}}== |
=={{header|Ada}}== |