Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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.

share|improve this question

closed as off-topic by belisarius, m_goldberg, Artes, Michael E2, rm -rf Nov 25 '13 at 20:43

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question arises due to a simple mistake such as a trivial syntax error, incorrect capitalization, spelling mistake, or other typographical error and is unlikely to help any future visitors, or else it is easily found in the documentation." – belisarius, Michael E2, rm -rf
If this question can be reworded to fit the rules in the help center, please edit the question.

    
I have a problem with " without replacement" –  mais Nov 25 '13 at 17:51
1  
Enter "random sample", with or without quotes, in the Documentation Center. Check amongst the top hits and you should find something applicable. –  Daniel Lichtblau Nov 25 '13 at 17:53
    
I didn't find anything about without replacement –  mais Nov 25 '13 at 18:06
2  
Click under Details. Always. –  Daniel Lichtblau Nov 25 '13 at 18:25
1  
@DanielLichtblau So surely you can answer here! –  belisarius Nov 25 '13 at 19:55

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!]}]
share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.