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()
def test_jumpahead_badstate(): rnd = Random() s, j = 4043161618, 2674112291824205302 rnd.init_by_array([s]) rnd.jumpahead(j) for i in range(500): r = rnd.random() assert r <= 1.0, (r, i)
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()
def rrandom_example(): rnd1 = Random() print rnd1.genrand32() # get a 32-bit random number print rnd1.random() # get a float random number x, 0.0 <= x < 1.0 seed = 1546979228 rnd2 = Random(seed) # set a seed print rnd2.random() print rnd1.state # you can access the internal state of the generator # change the internal state to one different from and likely far away from # the current state, n is a non-negative integer which is used to scramble # the current state vector. n = 10 rnd1.jumpahead(n) rnd1.random()