3 ms·
The method is on-line, that is, it doesn't need to know "n". Assuming I translated your above code correctly into Python, as: import random def incre
by dalke 11y ago
The method is on-line, that is, it doesn't need to know "n".
Assuming I translated your above code correctly into Python, as:
import random
def increasingRandomSequence(base, k, n):
while k > 0:
i = random.randrange(n - k + 1)
yield base + i
base += i+1
k -= 1
n -= i+1
then I checked the above using:
N = 6
counters = [0] * N
for i in range(100000):
for value in increasingRandomSequence(0, 5, N):
counters[value] += 1
print(counters)
and found a strong bias towards larger numbers. The counts are:
[50033, 75037, 87438, 93686, 96900, 96906]
which means 5 is in the hand much more often than 0.