I would have suspected the following code return comparable results:
import random
random.seed(765)
x = random.choices(range(34), k=100)
random.seed(765)
y = [random.choice(range(34)) for _ in range(100)]
But when we compare
>>> x[:5]
[1, 8, 9, 31, 29]
>>> y[:5]
[2, 30, 15, 26, 17]
clearly x is not equivalent to y.
I suspect that I a missing something obvious, but assumed the sequence set by the seed would have returned the same 100 values, regardless of choice vs choices with k = 100.
See the documentation:
For a given seed, the
choices()function with equal weighting typically produces a different sequence than repeated calls tochoice(). The algorithm used bychoices()uses floating point arithmetic for internal consistency and speed. The algorithm used bychoice()defaults to integer arithmetic with repeated selections to avoid small biases from round-off error.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With