mercredi 15 juillet 2020

Inconsistent random picks in Python with seed

I'm generating random numbers with a given seed.

The results I'm getting are inconsistent when I make a change that I wouldn't expect to have any impact.

CodeA:

#!/usr/bin/python
import sys
import random

random.seed(2610)
for x in range(0,100):
    pick1 = random.choice([1,2,3,4])
    pick2 = random.choice([1,2])
    print(pick2)

CodeB is exactly the same except that instead of picking out of 1,2,3,4 for pick1 I just pick out of 1,2,3. The output starts the same and then at around the 10th line, it starts diverging.

Interestingly, if I remove 3 and 4 (i.e., picking out [1,2]) then I get the same exact result.

My questions are:

  1. Is this a known problem or perhaps not even a problem?
  2. Is there a way around it such that I get the same output regardless of how many items I pick from for pick1?

Thanks!




Aucun commentaire:

Enregistrer un commentaire