In [1]:
import random
In [2]:
l = [0, 1, 2, 3, 4]
In [3]:
print(random.choices(l, k=3))
In [4]:
print(random.choices(l, k=10))
In [5]:
print(random.choices(l))
In [6]:
print(random.choices(l, k=3, weights=[1, 1, 1, 10, 1]))
In [7]:
print(random.choices(l, k=3, weights=[1, 1, 0, 0, 0]))
In [8]:
print(random.choices(l, k=3, cum_weights=[1, 2, 3, 13, 14]))
In [9]:
# print(random.choices(l, k=3, weights=[1, 1, 1, 10, 1, 1, 1]))
# ValueError: The number of weights does not match the population_
In [10]:
# print(random.choices(l, k=3, weights=[1, 1, 1, 10, 1], cum_weights=[1, 2, 3, 13, 14]))
# TypeError: Cannot specify both weights and cumulative weights