Alternate Random Sort?

Brian Yennie briany at qldlearning.com
Fri Jul 14 15:39:52 EDT 2006


Scott,

How about something like this. The idea being to loop through the lines 
and insert them into random keys of an array, then combine the array at 
the end.
This avoids any comparisons involved in sorting - it just sort of 
scatters them in the array and then pulls them back out. Also the 
random number is picked to be large so you only get a very small number 
of collisions forcing you to pick your random number more than once.

on mouseUp
   repeat 6000
     put 1 & cr after temp
   end repeat
   repeat 8000
     put 2 & cr after temp
   end repeat
   delete last char of temp
   put the millisecs into MS
   put empty into newValues
   put (number of lines in temp) into numLines
   put numLines*1000 into randomRange
   repeat for each line l in temp
     repeat
       put random(randomRange) into randomNumber
       if (newValues[randomNumber] is empty) then
         put l into newValues[randomNumber]
         exit repeat
       end if
     end repeat
   end repeat
   combine newValues using return
   put the millisecs - MS
end mouseUp




More information about the use-livecode mailing list