A85: Re: Random


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

A85: Re: Random




Why not simply use usgard's default built-in Random # function?  Here's a
segment of code from my current project (Under Usgard 1.5)for generating
random integers as an example:
;Generates random integer between 1 and L-1
;H is mask (Bit mask one bit higher than necessary, i.e. for 4-6 use 7)
;L is Desired max #+1
Randany:
 push hl
 call RANDOM
 pop hl
 AND h
 inc A
 cp l
 jr NC,Randany
 ret
;End Randany
I haven't tested it, but perhaps this would work..
;Push registers before calling
Random:
   call RANDOM
   and 3                 ;I want    -1,   0, or 1
   jr z,Random
   dec a
   dec a
-----Original Message-----
From: GrafixxHQ <GrafixxHQ@aol.com>
To: assembly-85@lists.ticalc.org <assembly-85@lists.ticalc.org>
Date: Sunday, January 04, 1998 10:32 PM
Subject: A85: Random


>
>I used this random routine in a Usgard game I am making:
>
>Random:
>   ld a,r
>   srl a
>   and 3                 ;I want    -1,   0, or 1
>   jr z,Random
>   dec a
>   dec a
>--------------
>The problem is that 1 comes up nearly all the time.
>Is there a way to make it more random, and give all the same probablity?
>Also, it seems that if I push the right arrow key, it never returns -1.
>
>I added "sub a" before the random, in case storing the key in the A
register
>was affecting the outcome, but that still didn't do anything.