Re: Randomly outputting an array



Ico <usenet@xxxxxxx> wrote:
Richard Heathfield <invalid@xxxxxxxxxxxxxxx> wrote:
ryanarossi@xxxxxxxxx said:

What would be the simplest way to output an array in random order, but
every element in the array MUST be outputted and the elements cannot
repeat? My current code is below, which I simply have a very large
array and I am outputting windows of an arbitary length.

OPTION BASE 0

DIM DECK(52) AS INTEGER
DIM N AS INTEGER
DIM R AS INTEGER
DIM T AS INTEGER

N = 52

REM Populate array
FOR J = 0 TO N - 1 STEP 1
DECK(J) = J
NEXT

REM Display in original order
FOR J = 0 TO N - 1 STEP 1
PRINT J;" ";
NEXT
PRINT

REM Shuffle
FOR J = 0 TO N - 1 STEP 1
R = INT(RND * (N - J)) + J
T = DECK(R)
DECK(R) = DECK(J)
DECK(J) = T
NEXT

Is N times swapping two elements considered enough to truly 'randomize'
an array ?

That was a stupid question, please ignore me...

--
:wq
^X^Cy^K^X^C^C^C^C
.