Showing results for 
Search instead for 
Did you mean: 
Reply

randomize array

randomize array

Hello all!

Does anyone have or know of a link to a VI that will randomize array
elements?

Thanks
Aaron

--
____________________________________________
Aaron Duley / aduley@ufl.edu
Motor Behavior & Performance Psychology Laboratories
http://www.hhp.ufl.edu/ess/mblab
Department of Exercise & Sport Sciences
College of Health & Human Performance
University of Florida
(352) 392-0580 x1378
100 Florida Gym R-132-D
PO Box 118207
Gainesville, Fl 32611
0 Kudos
Message 1 of 2 (1,617 Views)
Reply
0 Kudos

Re: randomize array

> Does anyone have or know of a link to a VI that will randomize array
> elements?
>

I don't have a VI, but I can describe how to build one pretty quickly.

The key is to select an array index and swap it with the last element
of the array. By swap, I mean index both and replace them with each
other. Then do the same operation, select a random array from the
elements ignoring the last, and swap it with the next to last. Do
this swap with another element of the array and statistically, you
are shuffled.

In more detail:
If your array length is N, indexed 0 through N-1, the first thing to
do is generate a number R, between 0 and N-1. Index two elements
from the array, R and N-1. Write the values back to the two
elements, but reversed. Next iteration generate a
number between
0 and N-2. Index with R and N-2, and swap.

You can do this with a For loop. Wire the array into a shift register.
Compute the random number from Array Size - 1 - i.

Greg McKaskle
0 Kudos
Message 2 of 2 (1,617 Views)
Reply
0 Kudos