classic-games.com

Atari 2600 Random Numbers

Date: Mon, 14 Apr 1997 15:59:12 +0000 (GMT)
From: emooney@stevens-tech.edu (Erik Mooney)
Subject: Re: [stella] demo update: PCMSD20.BIN
Sender: owner-stella@biglist.com
To: stella@biglist.com
Message-id: <335253a1.271125@attila.stevens-tech.edu>

>Hmmmm... can we see it? :)

I posted it a little while back, but here it is again for those of you who
missed it.  I'm using it for the bombs in my game, so it works at least
pretty well.

I did find the following algorithm: it uses a 31-bit register initialized
to any nonzero value.  A random bit is generated by XORing bits 27 and 30
of the register, then shifting the entire thing one bit to the left and
placing the new bit on the right.  If you want a random byte, simply call
the algorithm eight times and read the lowest 8 bits of the register.  This
algorithm produces a sequence of (2^31 - 1) random bits before repeating.
To seed the register, you can generate one random bit every frame whether
you need it or not; then, your register can have at least 200 different
values by the time the user presses Reset.

Some code for the procedure:
;Rand1, Rand2, Rand3, Rand4 are RAM locations, initialized to any nonzero
;value at program start (I use $6D)
;RandomBit generates one random bit.
;RandomByte generates one random byte and returns it in the accumulator.

RandomBit
    lda rand4
    asl
    asl
    asl
    eor rand4 ;new bit is now in bit 6 of A
    asl
    asl        ;new bit is now in carry
    rol rand1 ;shift new bit into bit 0 of register; bit 7 goes into carry
    rol rand2 ;shift old bit 7 into bit 8, etc.
    rol rand3
    rol rand4
    rts

RandomByte
    ldx #8
RandomByte1
    jsr RandomBit
    dex
    bne RandomByte1
    lda rand1
    rts


--
Archives available at http://www.biglist.com/lists/stella/archives/
E-mail UNSUBSCRIBE in the body to stella-request@biglist.com to be removed.
Classic Systems

Atari

Commodore

Nintendo

Vectrex

Other Systems

Game Database

List Games

Search

Submit Game

Other Options

Other Sections

Classic Games Index

Newer Video Games

Forums

Account Options

Articles

Store

Tools

Web Directory

Online Poker Bonuses

Online Casino Bonuses

Tradewars

Featured Games

Ancient Anguish

Get listed here!

Top Referrers

1. Stating the Obvious

Get listed here!

Click here to buy arcade cabinets and parts at Game Cabinets, Inc!

Latest News