Re: TIB: Random Number Generation Different From The One Before


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

Re: TIB: Random Number Generation Different From The One Before




In a message dated 2/24/99 5:48:43 PM Central Standard Time,
Jeanne9005@aol.com writes:

> On the 86, how do I get a random integer between 1 and 24, and then if the
>  number has already been used, it can't be used again?  Is there any shorter
>  way than testing all the numbers prior to it for the chosen number?  Please
>  don't waste mine and your time by telling me you don't have an 86.  Thanks 
> in
>  advance.
>  
>  Glen

This is convoluted and obscure, but it is the fastest possible algorithm.
What the program has to do is pick a number, and search a list to see if it's
in there.  The only real way to speed up this process is to use a binary
search (or bubble search, or whatever you want to call it) that can search a
sorted list in log(n) commands (n being the length of the list).  The other
searches were linear, using n commands.  The problem is, the code for a binary
search is obscure, unless you use a recursive function, and this is nearly
impossible on a Ti-86.  I'm working on it, but I don't have much time.  I'll
explain the theory here and maybe someone else can program it.
1.Make a list of the length you want
2.FOR LOOP: i = one to length
3.	store random number to a
4.	store one to n;
5.	RECURSION (may be possible with a loop)
6.         if list(n)=0 then store a to list(n);
7.         if a>list(n) then store 1+n*2 to n and go to recursion;
8.         if a<list(n) then store n*2 to n and go to recursion;
9.         decrement i

That's all, but remember that recursion is not the same as goto; that won't
work.
PJC II