dimanche 1 octobre 2023

Determine different seeds for which random shuffling list generates the same output

It is pretty intuitive that when shuffling a small enough collection, results will repeat themselves, even using different seeds each time, as it is just a matter of exhausting all unique combinations.

However, I can't find such information in the Python documentation. I am especially curious if there is any formula or algorithm to determine the different seed values for which the output would be identical. Is it possible to somehow forecast or calculate these seeds?

At first sight, I couldn't see any pattern or regular offset, and now it intrigues me if it's possible to find one 😁

I'm pasting the snippet of the code that I reproduced several times on my machine and within the online REPL.

import random

a = ["a", "b", "c", "d", "e"]
b = list(a)
c = list(a)

random.seed(0)
random.shuffle(a)
random.seed(344)
random.shuffle(b)
random.seed(496)
random.shuffle(c)

print(a == b == c == ["c", "b", "a", "e", "d"])  # True



Aucun commentaire:

Enregistrer un commentaire