I think Ry is on the right track: if you want the return value of random.sample
to be the same everytime it is called you will have to set random.seed
to the same value prior to every invocation of random.sample
.
Here are three simplified examples to illustrate:
random.seed(42)
idxT=[0,1,2,3,4,5,6]
for _ in range(2):
for _ in range(3):
print(random.sample(idxT, 3))
print()
[5, 0, 6]
[5, 2, 1]
[1, 6, 0]
[5, 6, 4]
[0, 4, 3]
[0, 6, 5]
idxT=[0,1,2,3,4,5,6]
for _ in range(2):
random.seed(42)
for _ in range(3):
print(random.sample(idxT, 3))
print()
[5, 0, 6]
[5, 2, 1]
[1, 6, 0]
[5, 0, 6]
[5, 2, 1]
[1, 6, 0]
idxT=[0,1,2,3,4,5,6]
for _ in range(2):
for _ in range(3):
random.seed(42)
print(random.sample(idxT, 3))
print()
[5, 0, 6]
[5, 0, 6]
[5, 0, 6]
[5, 0, 6]
[5, 0, 6]
[5, 0, 6]