예제 #1
0
 def f(x, y):
     x = r_uint(x)
     y = r_uint(y)
     rnd = Random(x)
     rnd.init_by_array([x, y])
     rnd.jumpahead(intmask(y))
     return float(rnd.genrand32()) + rnd.random()
예제 #2
0
 def f(x, y):
     x = r_uint(x)
     y = r_uint(y)
     rnd = Random(x)
     rnd.init_by_array([x, y])
     rnd.jumpahead(intmask(y))
     return float(rnd.genrand32()) + rnd.random()
예제 #3
0
def test_jumpahead():
    rnd = Random()
    rnd.state = [r_uint(0)] * N
    rnd.state[0] = r_uint(1)
    cpyrandom = _random.Random()
    cpyrandom.setstate(tuple([int(s) for s in rnd.state] + [rnd.index]))
    rnd.jumpahead(100)
    cpyrandom.jumpahead(100)
    assert tuple(rnd.state) + (rnd.index, ) == cpyrandom.getstate()
예제 #4
0
def test_init_by_array():
    rnd = Random()
    rnd.init_by_array([r_uint(n) for n in [1, 2, 3, 4]])
    assert rnd.state[:14] == [2147483648, 1269538435, 699006892, 381364451,
            172015551, 3237099449, 3609464087, 2187366456, 654585064,
            2665903765, 3735624613, 1241943673, 2038528247, 3774211972]
    # try arrays of various sizes to test for corner cases
    for size in [N, N - 1, N + 1, N // 2, 2 * N]:
        rnd.init_by_array([r_uint(n) for n in range(N)])
예제 #5
0
def test_jumpahead():
    rnd = Random()
    rnd.state = [r_uint(0)] * N
    rnd.state[0] = r_uint(1)
    cpyrandom = _random.Random()
    cpyrandom.setstate(tuple([int(s) for s in rnd.state] + [rnd.index]))
    rnd.jumpahead(100)
    cpyrandom.jumpahead(100)
    assert tuple(rnd.state) + (rnd.index, ) == cpyrandom.getstate()
예제 #6
0
def test_init_by_array():
    rnd = Random()
    rnd.init_by_array([r_uint(n) for n in [1, 2, 3, 4]])
    assert rnd.state[:14] == [
        2147483648, 1269538435, 699006892, 381364451, 172015551, 3237099449,
        3609464087, 2187366456, 654585064, 2665903765, 3735624613, 1241943673,
        2038528247, 3774211972
    ]
    # try arrays of various sizes to test for corner cases
    for size in [N, N - 1, N + 1, N // 2, 2 * N]:
        rnd.init_by_array([r_uint(n) for n in range(N)])