Re: Random choice
- To: mathgroup at smc.vnet.net
- Subject: [mg99839] Re: Random choice
- From: "Steve Luttrell" <steve at _removemefirst_luttrell.org.uk>
- Date: Fri, 15 May 2009 06:26:26 -0400 (EDT)
- References: <guj8ef$hv6$1@smc.vnet.net>
You need to do sampling without replacement. This code fragment will sample m times (without replacement) from a pool of n indices: n; m=5; Nest[({Append[#1[[1]],#1[[2,#2]]],Delete[#1[[2]],#2]}&[#,RandomInteger[{1,Length[#[[2]]]}]])&,{{},Range[n]},m] {{12,6,13,14,8},{1,2,3,4,5,7,9,10,11,15,16,17,18,19,20}} The code returns 2 lists: the sampled indices and the residue of the pool which was sampled from. This output can be fed back into the code fragment for further sampling if required. -- Stephen Luttrell West Malvern, UK "Valeri Astanoff" <astanoff at gmail.com> wrote in message news:guj8ef$hv6$1 at smc.vnet.net... > Good day, > > Given this example : > > In[1]:= RandomChoice[Range[500], 100] // Union // Length > > Out[1]= 91 > > what is the best way to get *exactly* 100 different > random numbers ranging from 1 to 500 ? > > Any piece of advice would be appreciated. > > -- > > Valeri Astanoff >