MathGroup Archive 2001

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Random Sampling Without Replacement?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg26596] Re: [mg26586] Random Sampling Without Replacement?
  • From: Matt.Johnson at autolivasp.com
  • Date: Thu, 11 Jan 2001 10:39:09 -0500 (EST)
  • Sender: owner-wri-mathgroup at wolfram.com

This may not be 'neat and compact', but it works (num is the number of
integers you want extracted from list):

ran[list_List, num_Integer] := Module[{list1},
    list1 = list;
    Do[list1 = Drop[list1, {Random[Integer, {1, Length[list1]}]}], {num}];
    Complement[list, list1]]

In[83]:=
ran[Range[10000], 3] // Timing
Out[83]=
{0.02 Second, {1958, 2146, 8036}}

-matt





"A. E. Siegman" <siegman at stanford.edu> on 01/08/2001 11:52:00 PM

cc:
Subject: [mg26596]  [mg26586] Random Sampling Without Replacement?



Looking for neat compact way to extract three distinct (i.e., nonequal)
randomly selected integers k1, k2, k3 from the range 1 to N (N > 3) --
in other words, random sampling without replacement -- ???







  • Prev by Date: Re: Random Sampling Without Replacement?
  • Next by Date: Re: Random Sampling Without Replacement
  • Previous by thread: Re: Random Sampling Without Replacement?
  • Next by thread: Re: Random Sampling Without Replacement?