How to resolve the algorithm Pseudo-random numbers/Combined recursive generator MRG32k3a step by step in the 11l programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Pseudo-random numbers/Combined recursive generator MRG32k3a step by step in the 11l programming language
Table of Contents
Problem Statement
numbers as shown above.
are as shown above
repetitions of
Is as follows:
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Pseudo-random numbers/Combined recursive generator MRG32k3a step by step in the 11l programming language
Source code in the 11l programming language
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)
You may also check:How to resolve the algorithm Higher-order functions step by step in the Elixir programming language
You may also check:How to resolve the algorithm Execute Brain step by step in the Haskell programming language
You may also check:How to resolve the algorithm Sorting algorithms/Bogosort step by step in the Kotlin programming language
You may also check:How to resolve the algorithm Pascal's triangle step by step in the Wren programming language
You may also check:How to resolve the algorithm Text processing/2 step by step in the Java programming language