Re: algorythm
This should do the trick:
function unique_sequence(integer num_entries,sequence range)
sequence s
integer n
s = {}
for i=1 to num_entries do
while 1 do
n = rand(range[2]+1-range[1])+range[1]-1
if not find(n,s) then
s &= n
exit
end if
end while
end for
return s
end function
? unique_sequence(5,{1,20})
-- END OF CODE
Note that it *does* have the possibility of ending up in an eternal loop,
but the odds of that ever happening is close to zip (unless to do something
stupid like unique_sequence(2,{1,1}) )
>hi anyone,
>
>is there an algorythm to determine sequences of 5 numbers in a given range
>(ex. 1 - 20) where each couple of numbers is used only once ?
>jos hermans
|
Not Categorized, Please Help
|
|