pick elements from the list randomly in uniform distribution without replacement

963 Views Asked by At

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?

1

There are 1 best solutions below

2
Vons On BEST ANSWER

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)