Re: LZ: Random help


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

Re: LZ: Random help



Steve Peterson wrote:
> 
> I need to know how to generate a random number between 11 and 108.  I
> need to have 120 bytes of memory set aside, but every number before 11
> and after 108 simply has to have a zero in it.  Is this possible...
> 
> I would appreciate any help I can get
> 


Well, that's not so easy... You could do something like this:


GetRandom:
 ld a,r
 srl a    ; Is this necessary? I've read that r reg never change the first bit.
 add a,11
 cp 109
 jr nc,GetRandom


This is NOT a good routine if you're going to many random numbers... just
make a test program and you'll see... The best way is to make your own
random number routine (I've got a short one if you're interested) which
will produce better numbers.


If you're just going to run that routine once in the program, it's a good
routine except that some numbers will show up much more often... (the
lower ones). That's because the range is 98. If you get a number between
99-127, it will rerandom (?) and the r register will increase with umm
10 (?) which means that numbers between 11-21 will be more common. I think
that's right, if I understand how the r register works.


<pre>
-- 
Real name: Jimmy Mårdell
Email....: mailto:mja@algonet.se
IRC-name.: Yarin
WWW......: http://www.algonet.se/~mja


"Strap me down with disillusion 
  Tie me up in lifelines
   Nothing stops my thoughts from breeding
    Nothing's stopping my mind" - Leather Strip
</pre>


References: