Coyote Graphics Routines

Date: Fri Mar 27 12:14:20 2015

single page | use frames     summary     class     fields     routine details     file attributes


top cgRandomIndices


result = cgRandomIndices(length, number [, SEED=long])

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

Author information



David W. Fanning 1645 Sheely Drive Fort Collins, CO 80526 USA Phone: 970-221-0438 E-mail: Coyote's Guide to IDL Programming:


Copyright (c) 2011, Fanning Software Consulting, Inc.


Change History:

Written, 22 December 2011 from an algorithm by JD Smith. David W. Fanning.

File attributes

Modification date: Fri Mar 27 11:07:39 2015
Lines: 118
Docformat: rst rst