All problems
Box-Muller Gaussian Pair Seeded
Problem
Generate a pair of independent standard normal values using the Box-Muller transform and two uniform values from a deterministic seeded linear congruential generator.
Take the square root of minus two times the log of the first uniform for the radius and twice pi times the second uniform for the angle, then return the cosine and sine components. Return both values as a list.
Hint
Adding one to the state and dividing by 2 to the 31 avoids the logarithm of zero.
Test cases
case 1
in: [0]
expected: [-2.757317421369682,-4.065728843223583]
case 2
in: [1]
expected: [0.519081643367445,1.0305939400147504]
case 3
in: [42]
expected: [-1.0319055258013532,-0.12916623646437947]
case 4
in: [7]
expected: [-0.309379456599555,0.9673535547282357]
Starter codePython
def box_muller_seeded(seed):
# Your code here
pass4 test cases · run your code against them in the editor