samedi 15 septembre 2018

Pick less than N objects randomly from K objects

Say you have 4 objects, 1,2,3,4. I would like to randomly pick 2 objects from here but it is also allowed not to pick any, or just pick 1 object. (Considering only the combination. No order.) So the possible states are the following 11 states.

[(empty)],[1],[2],[3],[4],[1,2],[1,3],[1,4],[2,3],[2,4],[3,4]

I would like to generate one of the states above at the possibility of once in 11 times.

I want to write generalized version of this. Pick less than N objects randomly from K objects.




Aucun commentaire:

Enregistrer un commentaire