A86: Fast Random Number Generation


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

A86: Fast Random Number Generation



I've been doing some experimenting to come up with a quick routine for
random number generation.  The routine below (47t without ret) is what I
have come up with.  The results are semi-random.  The same numbers keep
coming up, as you'd expect considering it's pulling opcodes off rom pages,
though the distribution seems fairly decent.  For my purposes, the actual
number doesn't matter as long as the distribution works.  Attached is the
skeleton program used to test the routine.  It just prints out six rows of
random numbers in hex.

 Speed is important, I don't want it to take longer to generate a random
number than it would to draw a sprite, as is the case with Mardell's
generator from ZTetris when using a large numbers for A.  If speed didn't
matter, I'd use his as it makes much better numbers than mine ;-)

Any suggestions/improvements?

; returns: a = psuedo random number
RandomNumber:
     ld a,r
   ld b,a
  add a,b
  ld c,a
  ld a,(bc)
  ld c,a
  ld a,(bc)
  xor b
  add a,c
  ret

--
David Phillips <david@acz.org>
http://www.acz.org/

randnum.asm