# Re: LZ: Random Numbers

```A.K.A. TheWiz wrote:
>
> > huh? this is a little confusing for me, all i need is the code or an
> > explanation (in moron terms) to produce a random number from 1-4 !
>   Random numbers are pretty complex... It might actually be SIMPLER to
> search the rom dump.  When you type Rand() in BASIC, you're calling an
> incredibly complex routine - else you wind up getting numbers that aren't
> random at all.
>   BTW, there's a bug in Tetris w/ the piece-selection algorithm - on
> occasion it will give you about 20 square blocks in a row!  This
> demonstrates the importance of getting good random numbers...
>
>                      /***********************************
>                      *           Daniel Knapp           *
>                      *       FeatherWate Software       *
>                      *     email: dankna@bergen.org     *
>                      *                                  *
>                      *      Whose account this is,      *
>                      *         I think I know.          *
>                      * The sysop is in Berkely, though. *
>                      * She will not see me typing here, *
>                      *        To watch this Mac         *
>                      *          Refuse to go.           *
>                      ***********************************/

I don't think anyone has enough time to search the whole dump for a TI_BASIC rand thing.
Besides, that gives a decimal random number from 0-1.  You would also need the int()
and multiply routines.  Kinda hard.

Now...there are two basic ways that I know of to have random numbers.  You can store a
number, do lots of sla's, rr's, or's, xor's and other chud, hopefully getting to a
pattern that doesn't repeat to often.  That's not very random, but it is fast.  RAND.ASM
at the source code archive has the routine for that.

Or...you could havea lookup table with scattered numbers 1-30 in any order., mixed up.
STart with a number, that's the pointer to the table, the number from that position is
the next pointer in the table, and so on.  Then, have a identical table with just 1-4's.
The pointer you get from the first table is also a pointer into the table of 1-4's.
Also, every once in a while, have the first table be moved over byte by byte.  This
shifts up the pointers so they point to differet numbers.  This is much slower, takes
up more memory, but is much more random.  It depends on the type of game you rae
making to which reoutine you want.  I have source for the second if you need it.

<pre>
--
Compliments of:
_-_-_-_-_-_-_-_
Alan Bailey
mailto:bailala@mw.sisna.com
IRC:Abalone
Web:http://www.mw.sisna.com/users/bailala/home.htm
</pre>

```

References:
• From: