Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

python random.choices vs random.sample

ll = list(range(10))

#random.sample only picks a number from the list ONCE
print(random.sample(ll, 10))
# [6, 9, 0, 2, 4, 3, 5, 1, 8, 7]

#random.choices can pick the same number twice or more
print(random.choices(ll, k=10))
# [5, 9, 5, 2, 7, 6, 2, 9, 9, 8]
#     ↑                 ↑  ↑
 
PREVIOUS NEXT
Tagged: #python
ADD COMMENT
Topic
Name
7+2 =