def main():
x = [randint(1,100) for i in range(1,100)]
return x
This returns 100 random numbers btw 1 and 100. Each time I call the function, it returns a different sequence of numbers. What I want to, is to get the same sequence of numbers each time. maybe saving the results into sth?
Here's a basic example patterned after your code
In both invocations, you get identical output. The key is, at any point you can retrieve and later reassign the current state of the rng.
The
random.seed
function has to be called just before a fresh call to random.You can provide some fixed seed.
For more information on seed: random.seed(): What does it do?