Re: A86: Another question. . .
[Prev][Next][Index][Thread]
Re: A86: Another question. . .
you can do the following:
ld a,r ;get refresh register
and $03 ;get # from 0-3
inc a ;now its # from 1-4
but it's kind of a sucky generator depending what you're using it for
(if you're using it, say, 100 times in a row, it really is bad 'cause it
repeats a lot). you can also use various routines for generating random
numbers. if you check out my TIESAQ source code on ticalc.org you will
find a routine that put a random # into HL. if you use it, you want to
do this:
call GetRand ;get the # into hl
ld a,l ;use only the lower byte - could be ld a,h also
and $03 ;get # from 0-3
inc a ;now its # from 1-4
if you want the max 2 b numbers that aren't a power of two, it gets
harder to do and also become slower, you have to write modulo routines,
etc.
Scott Noveck (SMN) wrote:
>
> OK, I solved the first problem (thanks Joshua =), but now I need to know the
> best way to figure random numbers with an upper limit (It'll probably be 4,
> but I'd rather have something where I can changethe max) -- so I want an
> integer between 1-4. I know the calc has a _RANDOM ROM cal, but I'm not
> sure how to use that -- and I'm pretty sure I've seen the r register used. .
> . So can someone send me a snipet of code that allows me to get a random
> number between 1 and whatever???
>
> S___________________________________________________C
> | The FIRST SimCity 3000 Site ~~ By Scott Noveck |
> 3_ http://sc3k.home.ml.org OR http://sc3k.base.org _K
> ______
> | |\ /| |\ |
> |_____ | \ / | | \ |
> | | v | | \ |
> ______| | | | \|
> -SMN
> noveck@pluto.njcc.com (preferable)
> SMN@geocities.com (slower)
--
=====================================
= =
= Kirk Meyer (mailto:_@ibm.net) =
= http://www.bigfoot.com/~kirkmeyer =
= =
= "Set your affection on things =
= above, not on things on the =
= earth." Colossians 3:2 =
= =
=====================================
References: