Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.sys.apple2.programmer > #4756

Re: Streamlining Applesoft - Random number generators

Newsgroups comp.sys.apple2.programmer
Date 2018-09-06 22:26 -0700
References <7dd16923-704e-4054-83f2-71be03ae9b92@googlegroups.com>
Message-ID <4e02b421-dd7f-47ad-98d9-ef838dafd70d@googlegroups.com> (permalink)
Subject Re: Streamlining Applesoft - Random number generators
From John Brooks <jbrooks@blueshiftinc.com>

Show all headers | View raw


> I am looking for generators that are comparatively small in size, are quite fast in its algorythm and does a good job of filling the hi-res screen to white using the test program.

For things like dissolves and crossfades where each value should be visited just once, my favorite is the 16-bit shift-xor prng which got heavy use in my AppleII and GS games:

300:46 4F 66 4E 90 06 A9 B4 45 4F 85 4F 60

Here's an example program which fills the screen randomly:

 5  REM PRNG demo. J.Brooks 9/6/2018
 10  HGR2 : HCOLOR= 3: POKE 79,1
 20  FOR I = 0 TO 65535: CALL 768
 30 R =  PEEK (78) +  PEEK (79) * 256 - 1
 40 Y =  INT (R / 280):X = R - (Y * 280)
 50  IF Y < 192 THEN  HPLOT X,Y
 60  NEXT : PRINT  CHR$ (7): GET A$: TEXT


> Are there other more efficient methods for random number generation than ones mentioned here that I may have overlooked?

Below is the RND function used in many of Datasoft's Apple/Atari/C64 games that were made in the late 80s. It's not the fastest PRNG, but it's pretty small, effective, and often fast enough.

-JB
@JBrooksBSI


* DATASOFT RND 6502
* BY JAMES GARON
* 10/02/86

RNDINIT
               LDA   #$AB
               STA   RNDSEED
               LDA   #$55
               STA   RNDSEED+1
               LDA   #$7E
               STA   RNDSEED+2
               RTS

* RESULT IN ACC
RND            LDA   RNDSEED
               ROL   RNDSEED
               EOR   RNDSEED
               ROR   RNDSEED
               INC   RNDSEED+1
               BNE   RND10
               LDA   RNDSEED+2
               INC   RNDSEED+2
RND10          ADC   RNDSEED+1
               BVC   RND20
               INC   RNDSEED+1
               BNE   RND20
               LDA   RNDSEED+2
               INC   RNDSEED+2
RND20          STA   RNDSEED
               RTS

Back to comp.sys.apple2.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Streamlining Applesoft - Random number generators gids.rs@sasktel.net - 2016-02-28 21:02 -0800
  Re: Streamlining Applesoft - Random number generators qkumba <peter.ferrie@gmail.com> - 2016-02-29 09:05 -0800
  Re: Streamlining Applesoft - Random number generators wssimms@gmail.com - 2016-02-29 09:07 -0800
    Re: Streamlining Applesoft - Random number generators Michael Pohoreski <michael.pohoreski@gmail.com> - 2016-02-29 12:57 -0800
    Re: Streamlining Applesoft - Random number generators "Michael J. Mahon" <mjmahon@aol.com> - 2016-02-29 17:50 -0800
  Re: Streamlining Applesoft - Random number generators Michael Barry <barrym95838@yahoo.com> - 2016-02-29 17:44 -0800
    Re: Streamlining Applesoft - Random number generators gids.rs@sasktel.net - 2016-02-29 18:38 -0800
    Re: Streamlining Applesoft - Random number generators "Michael J. Mahon" <mjmahon@aol.com> - 2016-02-29 18:46 -0800
    Re: Streamlining Applesoft - Random number generators wssimms@gmail.com - 2016-02-29 18:53 -0800
      Re: Streamlining Applesoft - Random number generators Michael Barry <barrym95838@yahoo.com> - 2016-03-01 00:11 -0800
        Re: Streamlining Applesoft - Random number generators wssimms@gmail.com - 2016-03-01 05:17 -0800
        Re: Streamlining Applesoft - Random number generators Michael J. Mahon <mjmahon@aol.com> - 2016-03-01 10:38 -0600
          Re: Streamlining Applesoft - Random number generators qkumba <peter.ferrie@gmail.com> - 2016-03-01 11:56 -0800
            Re: Streamlining Applesoft - Random number generators Michael Pohoreski <michael.pohoreski@gmail.com> - 2016-03-01 12:13 -0800
            Re: Streamlining Applesoft - Random number generators Michael J. Mahon <mjmahon@aol.com> - 2016-03-01 15:32 -0600
              Re: Streamlining Applesoft - Random number generators qkumba <peter.ferrie@gmail.com> - 2016-03-01 22:47 -0800
          Re: Streamlining Applesoft - Random number generators Michael J. Mahon <mjmahon@aol.com> - 2016-03-01 17:28 -0600
            Re: Streamlining Applesoft - Random number generators Michael Pohoreski <michael.pohoreski@gmail.com> - 2016-03-01 18:50 -0800
              Re: Streamlining Applesoft - Random number generators "Michael J. Mahon" <mjmahon@aol.com> - 2016-03-01 19:25 -0800
                Re: Streamlining Applesoft - Random number generators gids.rs@sasktel.net - 2016-03-01 22:03 -0800
                Re: Streamlining Applesoft - Random number generators "Michael J. Mahon" <mjmahon@aol.com> - 2016-03-02 20:49 -0800
                Re: Streamlining Applesoft - Random number generators "Michael J. Mahon" <mjmahon@aol.com> - 2016-03-03 14:48 -0800
              Re: Streamlining Applesoft - Random number generators "Michael J. Mahon" <mjmahon@aol.com> - 2016-03-01 20:02 -0800
                Re: Streamlining Applesoft - Random number generators Michael Pohoreski <michael.pohoreski@gmail.com> - 2016-03-03 07:48 -0800
                Re: Streamlining Applesoft - Random number generators gids.rs@sasktel.net - 2016-03-03 08:05 -0800
                Re: Streamlining Applesoft - Random number generators Michael Pohoreski <michael.pohoreski@gmail.com> - 2016-03-03 09:24 -0800
                Re: Streamlining Applesoft - Random number generators Michael J. Mahon <mjmahon@aol.com> - 2016-03-03 22:51 -0600
                Re: Streamlining Applesoft - Random number generators gids.rs@sasktel.net - 2016-03-03 21:34 -0800
                Re: Streamlining Applesoft - Random number generators Michael J. Mahon <mjmahon@aol.com> - 2016-03-04 00:50 -0600
                Re: Streamlining Applesoft - Random number generators Scott Hemphill <hemphill@hemphills.net> - 2016-03-04 10:47 -0500
                Re: Streamlining Applesoft - Random number generators qkumba <peter.ferrie@gmail.com> - 2018-09-05 20:41 -0700
                Re: Streamlining Applesoft - Random number generators Antoine Vignau <antoine.vignau@laposte.net> - 2018-09-06 09:13 -0700
                Re: Streamlining Applesoft - Random number generators qkumba <peter.ferrie@gmail.com> - 2018-09-06 10:33 -0700
                Re: Streamlining Applesoft - Random number generators Michael J. Mahon <mjmahon@aol.com> - 2018-09-06 17:58 -0500
  Re: Streamlining Applesoft - Random number generators John Brooks <jbrooks@blueshiftinc.com> - 2018-09-06 22:26 -0700
    Re: Streamlining Applesoft - Random number generators John Brooks <jbrooks@blueshiftinc.com> - 2018-09-07 18:08 -0700
    Re: Streamlining Applesoft - Random number generators John Brooks <jbrooks@blueshiftinc.com> - 2018-09-07 18:11 -0700
  Re: Streamlining Applesoft - Random number generators the.ertceps@gmail.com - 2018-09-29 05:03 -0700
    Re: Streamlining Applesoft - Random number generators James Davis <JPD.Enterprises@outlook.com> - 2018-09-29 10:24 -0700
      Re: Streamlining Applesoft - Random number generators Marco Verpelli <mverpelli@libero.it> - 2018-09-29 10:30 -0700
      Re: Streamlining Applesoft - Random number generators Brian Patrie <bpatrie@bellsouth.spamisicky.net> - 2018-09-29 12:36 -0500
        Re: Streamlining Applesoft - Random number generators Michael J. Mahon <mjmahon@aol.com> - 2018-09-29 12:41 -0500
          Re: Streamlining Applesoft - Random number generators Andy McFadden <thefadden@gmail.com> - 2018-09-29 21:06 -0700
          Re: Streamlining Applesoft - Random number generators James Davis <JPD.Enterprises@outlook.com> - 2018-09-30 19:28 -0700
            Re: Streamlining Applesoft - Random number generators "Frank M." <frank_o_rama@hotmail.com> - 2018-10-01 07:27 -0700

csiph-web