Xref: utzoo comp.sources.wanted:7439 alt.msdos.programmer:51 Path: utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!uwvax!dogie.macc.wisc.edu!indri!polyslo!csun!csuna!abcscnge From: abcscnge@csuna.csun.edu (Scott "The Pseudo-Hacker" Neugroschl) Newsgroups: comp.sources.wanted,alt.msdos.programmer Subject: Re: Need algorithm to scramble order of array Message-ID: <1975@csuna.csun.edu> Date: 18 May 89 06:50:03 GMT References: <3008@cps3xx.UUCP> Reply-To: abcscnge@csuna.csun.edu (Scott Neugroschl) Organization: CSU Northridge Lines: 30 In article <3008@cps3xx.UUCP> reedp@frith.egr.msu.edu () writes: ]I need a fast algorithm to randomly rearrange the order of elements in ]an array. Right now I am just using a random number generator to form ]a list of numbers that directly determines the order of the array like this: ] ] n = size of array ] ] for i = 1 to n ] { ] do ] x = random number between 1 and n ] while x is not already in list[] ] ] list[i] = x ] } ] list = array N = size of list for i from N down to 2 do x = random number between 1 and i inclusive swap list[i] and list[x] end for -- Scott "The Pseudo-Hacker" Neugroschl UUCP: ...!sm.unisys.com!csun!csuna.csun.edu!abcscnge -- Beat me, Whip me, make me code in Ada -- Disclaimers? We don't need no stinking disclaimers!!!