Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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 Dr. belisarius, m_goldberg, Artes, Michael E2, R. M. 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." – Dr. belisarius, Michael E2, R. M.
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
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
Click under Details. Always. – Daniel Lichtblau Nov 25 '13 at 18:25
@DanielLichtblau So surely you can answer here! – Dr. belisarius Nov 25 '13 at 19:55

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".. 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,


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.