简体   繁体   中英

pick elements from the list randomly in uniform distribution without replacement

I have a list that ranges from 0 to 30

arr = range(0,30)

I need to pick a sample of "m" elements from the list using uniform distribution without replacement. I used random.uniform() which gives the random value in float.

Can anyone tell me how to pick the "m" elements from the given list randomly using uniform distribution without replacement?

You may use the random.sample to take a sample without replacement

# Python3 program to demonstrate
# the use of sample() function

# import random
from random import sample

# Prints list of random items of given length
arr = range(0,30)

m=5

mysamp = sample(arr,m)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM