PDA

View Full Version : randomly-ordered indices?



hcrisp
02-11-2011, 10:49 AM
Let's say I have a vector for known, unique indices, but I want to address them one at a time in random order. Is there a PV-WAVE function that will generate this random index vector with one call? I looked in the Stats manual, but none of the Random Number Generation routines seem capable of doing this. Uniform distribution is fine.



ids = LINDGEN(25)
; I want a function that does this:
; rnd_ids = RANDOM_ORDER(ids)
; PRINT, rnd_ids
; 23, 2, 15, 0, 17, 1, etc.

omega
02-11-2011, 11:11 AM
Perhaps start with the IMSL Stat routine RANDOM using the keyword Permutation. Also, depending upon your precise needs, other RANDOM keywords to look at include Sample_indices and Discrete_uniform.

hth,
-w

hcrisp
02-11-2011, 11:24 AM
Thank you. That works nicely.



PRINT, RANDOM(25, /PERMUTATION)-1

; If you need to randomly order a finite index array:

ids = LINDGEN(25)*2 + 7
PRINT, ids(RANDOM(25, /PERMUTATION)-1)