mercredi 6 janvier 2021

Python's random choices gives the same array every invocation

I using Python's random.choices inside a while loop and its result is always the same which makes my loop infinite:

object_one = object_two = None
while object_two == object_one:
            object_one, object_two = random.choices(population, weights=weights, k=2)

I've checked and the weights are almost the same, and len(population) is over 300. It is not easy to reproduce, it happened twice out of dozens of tries. I've looked online and it seems that this is not a known bug. Why is it happening and how can I be sure it won't happen in other randomness package (numpy's random for example)?




Aucun commentaire:

Enregistrer un commentaire