What is the module that selects a random sample of size k (without replacement) from a given population of size n, involving the command Subsets.

=================

=================

1 Answer

1

=================

Well, they don’t literally use the terminology “without replacement” in the manual, but One might expect you should know that is the same as saying “no elements occur more then once”..

Anyway..in summary there are two related functions:

RandomSample[list,k] -> “without replacement”

RandomChoice[list,k] -> “with replacement”

And to literally answer the question, if you insist on using Subsets,

RandomChoice@Subsets[list,{k}]

will also give a sample “without replacement”. Note Subsets approach will be horribly slow for large lists since it generates all combinations then picks one. (Subsets also orders the result which you may or may not want)

Just for fun you get respectable performance out of Subsets if you do this:

Subsets[list,{k},{RandomInteger[ Length[list]! / (Length[list]-k)! / k!]}]