Random but unique, more info
Jim Lambert
jiml at netrin.com
Sat Jan 11 18:07:01 EST 2003
>VChooseFrom is a list containing numbers:
> 1
> 2
> 3
> 4
> 5
> 6
> 7
> 8
> 9
> 10
> 11
> 12
> and so on...
>
>VNumToChoose contains the number of lines to randomly select from
>ChooseFrom: 5
>
>How do I pick randomly five lines out of vChooseFrom, putting them into
>vSelected
If VChooseFrom is literally a list of sequential numbers starting at 1, as
noted above, then you could use this function where maxNum is the number of
lines in VChooseFrom.
function getrndlines maxNum, VNumToChoose
repeat until the number of lines of temp = VNumToChoose
put random(maxNum) into thisNum
if thisNum is not among the lines of temp then put thisNum & return
after temp
end repeat
delete the last char of temp
return temp
end getrndlines
You could save RAM by making VChooseFrom simply maxNum. That is to say, if
VChooseFrom is 1 through 125, why not just say VChooseFrom = 125?
Jim Lambert
More information about the use-livecode
mailing list