Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2001
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2001

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

Search the Archive

Re: Random Sampling Without Replacement?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg26605] Re: Random Sampling Without Replacement?
  • From: jorma.virtamo at hut.fi
  • Date: Thu, 11 Jan 2001 10:39:15 -0500 (EST)
  • Organization: Helsinki University of Technology
  • References: <93edpc$cn@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Here is one way, though not very compact:

rnd[n_] := Module[{k1,k2,k3},
k1=Random[Integer,{1,n}];
k2=Random[Integer,{1,n-1}]; If[k2>=k1,k2++];
k3=Random[Integer,{1,n-2}]; If[k3>=Min[k1,k2], k3++; If[k3>=Max[k1,k2],
k3++]];
{k1,k2,k3}]

For instance:

Table[rnd[5],{10}]
{{1, 4, 3}, {1, 2, 5}, {4, 2, 5}, {1, 4, 2}, {4, 2, 1}, {3, 5, 4}, {5, 4,
3}, {1, 3, 5},
  {1, 4, 5}, {3, 4, 5}}

Jorma Virtamo

"A. E. Siegman" wrote:

> 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?