Random but unique, more info

Rob Cozens rcozens at pon.net
Sat Jan 11 16:02:01 EST 2003


>How do I pick randomly five lines out of vChooseFrom, putting them into
>vSelected:

function randomList vNumToChoose, at vChooseFrom
   put return into vSelected
   add 1 to vNumToChoose
   repeat while the number of lines of vSelected < vNumToChoose
     get (any line of VChooseFrom)&return
     if offset(return&it,vSelected) = 0 then put it after vSelected
   end repeat
   return char 2 to -1 of vSelected
end randomList

If vNumToChoose is relatively small compared to the number of lines 
of vChooseFrom, this should be reasonably efficient.  If vNumToChoose 
is relatively close to the number of lines of vChooseFrom, it will 
require significantly more repeats to do the job; thus Dar's "delete 
from list approach" may provide better performance.
-- 

Rob Cozens
CCW, Serendipity Software Company
http://www.oenolog.com/who.htm

"And I, which was two fooles, do so grow three;
Who are a little wise, the best fooles bee."

from "The Triple Foole" by John Donne (1572-1631)



More information about the use-livecode mailing list