This function returns random indices without replacement. You can, for example, select 100 random, unique indices from a vector of 10000 random indices.
The program uses an algorithm offered by JD Smith on the IDL newsgroup.
- length in required type=long
The number of random values to be considered in the selection process. In other words, the length of the selection vector.
- number in required type=long
The number of unique, random indices you want the function to return out of the selection vector.
- SEED in optional type=long
The seed for the random number generator, RandomU. This is also an output variable, which you should use as the input to the next cgRandomIndices call, if you need to do several random selections very quickly in a program.
To select 10 random indices from a list of 100:
indices = cgRandomIndices(100, 10, SEED=seed) Print, indices 7 13 20 21 32 44 50 66 80 93
FANNING SOFTWARE CONSULTING:
David W. Fanning 1645 Sheely Drive Fort Collins, CO 80526 USA Phone: 970-221-0438 E-mail: firstname.lastname@example.org Coyote's Guide to IDL Programming: http://www.idlcoyote.com
Copyright (c) 2011, Fanning Software Consulting, Inc.
Written, 22 December 2011 from an algorithm by JD Smith. David W. Fanning.
|Modification date:||Fri Mar 27 11:07:39 2015|