Search
 
SCRIPT & CODE EXAMPLE
 

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]
#     ↑                 ↑  ↑
Comment

PREVIOUS NEXT
Code Example
Python :: python read file csv 
Python :: cv display image in full screen 
Python :: python console animation 
Python :: select items from dataframe where value is null 
Python :: django runserver 
Python :: How to update python using anaconda/conda 
Python :: get current month python 
Python :: get size of window tkinter 
Python :: E tensorflow/stream_executor/cuda/cuda_dnn.cc:329] Could not create cudnn handle: CUDNN_STATUS_INTERNAL_ERROR 
Python :: how to get all links from a website python beautifulsoup 
Python :: python get index of item in 2d list 
Python :: knowing the sum of null value is pandas dataframe 
Python :: python json dump utf8 
Python :: discord.py send image 
Python :: text to speech python 
Python :: print specific part in bold or colours and end. 
Python :: f string curency format 
Python :: how to place image in tkinter 
Python :: how to remove first row of numpy array 
Python :: how to extract month from date in python 
Python :: pandas standardscaler 
Python :: pyspark session 
Python :: get all file names in a folder python 
Python :: create new thread python 
Python :: split filename and extension python 
Python :: figure title python 
Python :: generate openai schema 
Python :: python fiscal year prior 
Python :: django secret key 
Python :: how to change opencv capture resolution 
ADD CONTENT
Topic
Content
Source link
Name
7+9 =