Xref: utzoo comp.sources.wanted:7418 alt.msdos.programmer:42 Path: utzoo!attcan!uunet!pyrdc!grebyn!scotth From: scotth@grebyn.COM (Scott Hutchinson) Newsgroups: comp.sources.wanted,alt.msdos.programmer Subject: Re: Need algorithm to scramble order of array Message-ID: <11998@grebyn.COM> Date: 17 May 89 17:42:01 GMT References: <3008@cps3xx.UUCP> Reply-To: scotth@grebyn (Scott Hutchinson) Organization: Grebyn Corp. & Timesharing Customers; Vienna, VA Lines: 30 In article <3008@cps3xx.UUCP> reedp@frith.egr.msu.edu () writes: >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! How about filling the array initially with the numbers in order, then just doing random swaps. like: int i[100]; int j; for (j=0; j<100; j++) i[j]=j; for (j=0; j< some number of swaps; j++) swap(i[j],i[(j+j*2) % 100]) This seems like it should scramble the list. By the way, in case you don't know C, the % 100 is a modulo 100. -Scott Hutchinson -- ---------------------------------------------------------------------------- Standard Disclamers: These opinions are mine, they do not reflect on my Company at all. I can be reached at scotth@grebyn.com or scotth@grebyn.uucp