Re: algorythm

new topic     » goto parent     » topic index » view thread      » older message » newer message

sorry, but this prog is not quite what i'm looking for.
what I need is "all" sequences, with every couple of numbers just used once.
This one produces only 1 sequence, and isn't calculated, but just picked
randomly.


Jos


----- Original Message -----
From: <stabmaster_ at hotmail.com>
To: "EUforum" <EUforum at topica.com>
Sent: Thursday, April 10, 2003 1:15 PM
Subject: 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
>
>
>
> TOPICA - Start your own email discussion group. FREE!
>
>

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu