Xref: utzoo comp.sources.wanted:7414 alt.msdos.programmer:39 Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!rutgers!netnews.upenn.edu!eecae!cps3xx!usenet From: usenet@cps3xx.UUCP (Usenet file owner) Newsgroups: comp.sources.wanted,alt.msdos.programmer Subject: Need algorithm to scramble order of array Message-ID: <3008@cps3xx.UUCP> Date: 17 May 89 13:55:19 GMT Reply-To: reedp@frith.egr.msu.edu () Organization: Michigan State University, Engineering, E. Lansing Lines: 23 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 } The problem is that as the list fills up with numbers, the time spent in the do loop getting a number not already in the list grows very large. Does anyone know of a better way to do this? Any help would be greatly appreciated! Paul Reed Internet: reedp@horus.cem.msu.edu Bitnet: reedp@MSUCEM