In [1]:
import random

In [2]:
l = [0, 1, 2, 3, 4]

In [3]:
print(random.choices(l, k=3))


[2, 1, 0]

In [4]:
print(random.choices(l, k=10))


[3, 4, 1, 4, 4, 2, 0, 4, 2, 0]

In [5]:
print(random.choices(l))


[1]

In [6]:
print(random.choices(l, k=3, weights=[1, 1, 1, 10, 1]))


[0, 2, 3]

In [7]:
print(random.choices(l, k=3, weights=[1, 1, 0, 0, 0]))


[0, 1, 1]

In [8]:
print(random.choices(l, k=3, cum_weights=[1, 2, 3, 13, 14]))


[3, 2, 3]

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