Beispiel #1
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()
Beispiel #2
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()
Beispiel #3
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)])
Beispiel #4
0
def test_translate():
    from pypy.translator.interactive import Translation
    def f(x, y):
        rnd = Random(x)
        rnd.init_by_array([x, y])
        rnd.jumpahead(intmask(y))
        return rnd.genrand32(), rnd.random()
    t = Translation(f)
    fc = t.compile_c([r_uint, r_uint])
    assert fc(r_uint(1), r_uint(2)) == f(r_uint(1), r_uint(2))