Re: Random Sampling Without Replacement
- To: mathgroup at smc.vnet.net
- Subject: [mg26594] Re: Random Sampling Without Replacement
- From: "Ersek, Ted R" <ErsekTR at navair.navy.mil>
- Date: Thu, 11 Jan 2001 10:39:08 -0500 (EST)
- Sender: owner-wri-mathgroup at wolfram.com
A. E. Seigman wanted a neat compact way to randomly selected three integers
from 1 to N (N>3). Everything needed is in a standard package.
In[1]:=
<<DiscreteMath`Combinatorica`
For three random numbers between 1 and 50 use:
In[2]:=
Part[ RandomKSubset[Range[50], 3], RandomPermutation[3] ]
Out[2]=
{14, 12, 38}
You can also use RandomPermutation1 or RandomPermutation2 instead of
RandomPermutation which are in the same package. However, I haven't figured
out the difference between the three types. You can also check the
implementation of the package to possibly get ideas on how to make it work
faster.
--------------------
Regards,
Ted Ersek
Download Mathematica tips, tricks from
http://www.verbeia.com/mathematica/tips/Tricks.html