Re: TIB: mixing up a list


[Prev][Next][Index][Thread]

Re: TIB: mixing up a list




On Thu, 13 May 1999 20:43:33 EDT, McBorder@aol.com wrote:

>Ok i have a list of 56 elements. 26 1's and 26 2's. what is the fastest way 
>i
>can mix them up, or create a list with 26 1's and 26 2's in random order
>right now i have two for loops that pick a random spot in the list and put 
>in
>a number
>ex
>
>For(a,1,26
>Lbl gn
>randint(1,52)\->\b
>if cards(b)<>0                 <> means not equal to
>goto gn
>1\->\cards(b)
>end
>For(a,1,26
>Lbl gn2
>randint(1,52)\->\b
>if cards(b)<>0                 <> means not equal to
>goto gn2
>2\->\cards(b)
>end
>
>this code slows down as the last numbers are filled so i need a faster way 
>to
>do this
>
>	thanks
>	matt c
>	http://junkworld.cjb.net

Okay, the problem is that towards the end, most elements of the list are 
full, therefore it can take a while to find an element that is empty. If you 
try something like this, I think you'll find it's faster:

Fill(0,cards)
For(a,1,26
Lbl gn
randint(1,52)\->\b
if cards(b)<>0                 <> means not equal to
goto gn
1\->\cards(b)
end
For(a,1,52
if cards(a)=0
2\->\cards(a)
End

The difference is that the second for loop only scans the whole list and 
fills the empty elements with 2's, because the 1's are already in.

James Vernon
jimbob_v@hotmail.com


______________________________________________________
Get Your Private, Free Email at http://www.hotmail.com