MathGroup Archive 2001

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

Search the Archive

Re: Random Sampling Without Replacement?


"A. E. Siegman" <siegman at stanford.edu> wrote in message
news:93edpc$cn at smc.vnet.net...
> 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 -- ???

According to D. Knuth, The Art of Computer Programming, Vol. 2, 3rd ed.,
Ch. 3.4.2, exercise 16, and D. Ripley, Stochastic Simulation, p. 80,
the following simple code also works:

{nn, n} = {52, 3};
result = {};
While[Length[result] < n,
          result = Union[Append[result, Random[Integer, {1, nn}]]]];
result

With best regards
Hermann Meier



  • Prev by Date: erratum in OnLineHelp & TheBook
  • Next by Date: Re: Re: Random Sampling Without Replacement?
  • Previous by thread: Re: Random Sampling Without Replacement?
  • Next by thread: Re: Re: Random Sampling Without Replacement?