pick randomly a certain fraction of numbers from a list

Yuval yuvalfeld at hotmail.com
Fri Feb 14 13:32:52 EST 2003


Does anybody know a quick way of picking randomly x% of elements from a list. 
e.g. If I have a list of 50 elements, how do I randomly choose 2% of it? 
The trivial way would be to iterate with the random.choice() function. 
Is there any better way? 

Thanks.




More information about the Python-list mailing list