dimanche 15 septembre 2019

Finding a seed that generates the same random numbers

I've been thinking about an interesting problem and want to figure out how to solve it.

I want to find a seed that generates the same random numbers, specifically I want find a seed that the first random.getrandombits(32) will be equal to some value in the function 3x + 1 with the domain 1<=x<=99.

For example: I want to find a seed i in which for some index j random.getrandombits(32) == (the 3j + 1th generation of) random.getrandbits(32)

I've tried bruteforcing it in python but that didnt go so well. Here's the script I have so far:

import random, sys

# Find seed in the range of 1-1,100000000
for i in range(1,100000000):
    random.seed(i)
    # Get first random number
    first = random.getrandbits(32)
    print("In {}".format(i))
    # Test for first 100 numbers
    for j in range(100):
            if (j != 0): random.getrandbits(32)
            current = random.getrandbits(32)
            # Found seed in which it occurs
            if (current == first):
                    print(i,j)
                    sys.exit(0)
            random.getrandbits(32)
    print("Done {}".format(i))




Aucun commentaire:

Enregistrer un commentaire