Question

I am writing a script where I have a list of 7 integers ranging from 66 to 95. I want this list to be pseudo-randomly different each time I call it, but I want to be sure that it never returns the same random arrangement of random numbers.

This is nestled earlier in the file:

rnd = random.Random()

If I set x to 1 in the seed and call the function like so:

rnd.seed(x)
results = [rnd.randrange(66, 96) for i in range(7)]

and then if I call the function over and over, incrementally adding 1 to x in:

rnd.seed(x)

Will I be guaranteed a different set of random arrangements of random numbers until the number of possible iterations loops? When I write this down I feel like the answer is no. And if the answer is no, is there a way to do this? The program will be opened and closed often and if this works I would start it on the seed it last closed on.

Était-ce utile?

La solution

There's absolutely no way to guarantee that generating a random list of 7 integers will always be unique, short of checking the newly generated list against a database of all generated lists you've already created. Random is random, and although the chance is slim (1 in 21,870,000,000 to be precise) it will always be possible without some sort of verification of uniqueness.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top