mercredi 15 juin 2016

How to pull a random sample from an array in Python? [duplicate]

This question already has an answer here:

How do you pull a random sample from an array in Python?

Say that you have the following array that is a hat full of names:

names=["Ben","John","Alex","David","Jacob"]

If I wanted to pull TWO random names, and have the value removed so it cannot be pulled again, how would I do that? I need this for a python script that has 54 objects, and need to pull 8 random objects from it and they cannot be pulled more than once.

Thank you! :)

edit: yes, I've searched here already. This question differs because it is random sample WITH replacement. thanks again




Aucun commentaire:

Enregistrer un commentaire