another fix to shuffle

This commit is contained in:
gmega 2024-11-27 11:36:17 -03:00
parent 586932f67e
commit ccfc7614a7
No known key found for this signature in database
GPG Key ID: 6290D34EAD824B18

View File

@ -63,7 +63,7 @@ def sample(n: int) -> Iterator[int]:
"""Samples without replacement using a basic Fisher-Yates shuffle.""" """Samples without replacement using a basic Fisher-Yates shuffle."""
p = list(range(0, n)) p = list(range(0, n))
for i in range(n - 1): for i in range(n - 1):
j = i + random.randint(0, n - i) j = random.randint(i, n - 1)
tmp = p[j] tmp = p[j]
p[j] = p[i] p[j] = p[i]
p[i] = tmp p[i] = tmp