Beispiel #1
0


def rand_to_state(y):
    y = undo_right_shift(y, l)
    y = undo_left_shift(y, t, c)
    y = undo_left_shift(y, s, b)
    y = undo_right_shift(y, u, d)
    return y


def state_to_rand(y):
    y = y ^ ((y >> u) & d)
    y = y ^ ((y << s) & b)
    y = y ^ ((y << t) & c)
    y = y ^ (y >> l)
    return y


seed = 22131
orig = Random(seed)
clone = Random(0)

for i in range(624):
    output = orig.next_int()
    state = rand_to_state(output)
    clone.x[i] = state

for i in range(100):
    print orig.next_int(), clone.next_int()
Beispiel #2
0
def stream(seed):
    seed = seed & 0xffff  # 16-bit seed
    rand = Random(seed)
    while True:
        yield rand.next_int() & 0xff