swarm-support
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

sample collection without replacement


From: Rick Riolo
Subject: sample collection without replacement
Date: Wed, 21 Aug 1996 14:40:44 -0400 (EDT)

I'd like to know the recommended way to get
some random samples without replacement from a collection (in particular
a list if it matters).  Here is (basically) the way I do it now:

    index = [agents begin: scratchZone];
    numAgents = [agents getCount];   // actually I don't use getCount for this
    for ( n = 0; n < sampleSize; ++n ) {
        t = [uniformRandomR rMax: numAgents];
        agnt = [index setOffset: t];
        // do whatever with agnt here...
        [index remove];
        --numAgents;
    } [index dropFrom: scratchZone];

Is there a better or built in way to do this?

If this is an ok way to do it, it would be a bit
cleaner if index supported a getCount method (which I guess
it doesn't, despite Collection supporting it).
Any reason why it doesn't (if it doesn't)?

thanks!
  - r

Rick Riolo                       address@hidden
Program for Study of Complex Systems (PSCS)
1061 Randall Lab     University of Michigan
Ann Arbor MI 48109-1120
http://pscs.physics.lsa.umich.edu/rlr-home.html



reply via email to

[Prev in Thread] Current Thread [Next in Thread]