Home > other >  pick elements from the list randomly in uniform distribution without replacement
pick elements from the list randomly in uniform distribution without replacement

Time:11-30

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?

CodePudding user response:

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)
  • Related