by loverofthings · 8y ago · 0 comments
Code snippets shown use modulus (x % (N+1)) to accomplish that. This will result in the numbers not at all uniformly distributed.
Of course, the differences in probability aren't that huge but the contracts are mathematically not fair.
import numpy as np
n, m = 2, 20
binc = np.bincount(np.random.randint(0, m, size=20000000) % (n+1))
print 1.0*binc/sum(binc);
[0.3501464 0.3497516 0.300102 ]
When we're generating 0-2, from 0-20, we get 0 and 1 more often than 2.No comments yet.