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


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

Re: Streamlining Applesoft - Random number generators

Path csiph.com!usenet.blueworldhosting.com!feeder01.blueworldhosting.com!peer03.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!Xl.tags.giganews.com!border1.nntp.dca1.giganews.com!nntp.giganews.com!local2.nntp.dca.giganews.com!news.giganews.com.POSTED!not-for-mail
NNTP-Posting-Date Fri, 04 Mar 2016 09:47:13 -0600
From Scott Hemphill <hemphill@hemphills.net>
Newsgroups comp.sys.apple2.programmer
Subject Re: Streamlining Applesoft - Random number generators
References <7dd16923-704e-4054-83f2-71be03ae9b92@googlegroups.com> <90a30bbe-9288-49c6-9728-624896a627bd@googlegroups.com> <754e0a85-0ee0-4b7d-8d97-16f4f60f4b17@googlegroups.com> <99335f72-8384-4cd8-b719-cbbe86e7b130@googlegroups.com> <LfydnYAW4KLyWEjLnZ2dnUU7-THNnZ2d@giganews.com> <yPGdnXoigtEPuEvLnZ2dnUU7-evNnZ2d@giganews.com> <0d7e1711-4586-4203-9825-5229a1c64b08@googlegroups.com> <xaudncrlbLxK-EvLnZ2dnUU7-LfNnZ2d@giganews.com> <6d52de94-fc33-423d-abdb-fad2ec5af67e@googlegroups.com> <ysydnSecMKD8iUTLnZ2dnUU7-LHNnZ2d@giganews.com> <b798ece7-5b0d-44d6-ab1d-aee6dee0e8ab@googlegroups.com> <7NadnThcNNnNrUTLnZ2dnUU7-KfNnZ2d@giganews.com>
Reply-To hemphill@alumni.caltech.edu
Date Fri, 04 Mar 2016 10:47:13 -0500
Message-ID <87ziue2qke.fsf@hemphills.net> (permalink)
User-Agent Gnus/5.13 (Gnus v5.13) Emacs/24.5 (gnu/linux)
Cancel-Lock sha1:AYJLS19Fa0QUS54qff9WyzNyFqU=
MIME-Version 1.0
Content-Type text/plain
Lines 95
X-Usenet-Provider http://www.giganews.com
X-Trace sv3-3uI5OmYSLVkZQ77DumpgnbfVAoXc1ksa/FvpQUycmTCtG7H4iTzSb67hMqNKOohHlm4Bc9s/li/yHPi!FeC3lzID5mebjv7O/AXyYrE0mjMfiwuqU0Zg6vAS/hhOajWBTDq9uMw=
X-Complaints-To abuse@giganews.com
X-DMCA-Notifications http://www.giganews.com/info/dmca.html
X-Abuse-and-DMCA-Info Please be sure to forward a copy of ALL headers
X-Abuse-and-DMCA-Info Otherwise we will be unable to process your complaint properly
X-Postfilter 1.3.40
X-Original-Bytes 5048
X-Received-Bytes 5160
X-Received-Body-CRC 3468296201
Xref csiph.com comp.sys.apple2.programmer:2429

Show key headers only | View raw


Michael J. Mahon <mjmahon@aol.com> writes:

> <gids.rs@sasktel.net> wrote:
>>>> Thanks Michael! That's *exactly* the code I was thinking of -- just
>>>> couldn't remember the name (or location).
>>>> 
>>>> Pity that AppleSoft doesn't use the 16-bit RNDL and RNDH as part
>>>> of its seed. :-/
>>> 
>>> When debugging, you want deterministic pseudorandom numbers.  You can
>>> always PEEK the GETCHR counter and use it to seed RND if you want a
>>> different set each time. 
>>> 
>>> By default, RND delivers the same sequence each time after a cold start
>>> (assuming that the uninitialized low byte of the seed powers up in the same
>>> state ;-).
>>> 
>>> If you really want to be sure the same sequence occurs on each run, you
>>> should seed RND at the start of your program, though a good fraction of
>>> seeds seem to deliver a modest pseudorandom sequence followed by a short
>>> cycle...
>> 
>> 
>> For the IIGS anyways, I think the VBL and HBL would be an excellent
>> source for a seed on startup.  These values are always random and when
>> used in conjunction with RNDL and RNDH can give a 4-byte random seed, and
>> you can even give a random key press for a 5th byte, different every
>> time on bootup.
>> 
>> I use this for a 5 byte random seed in Sweet 16 and GSPORT and real IIGS.
>> I believe this should work in a IIc as well but not II+ or IIe's
>> standard or enhanced.
>> 
>> ]LOOP INC $4E
>>  BNE NOTHI
>>  INC $4F
>> NOTHI BIT $C000
>>  BPL ]LOOP
>>  LDA $C010
>>  STA $C9
>>  LDX $C02E
>>  LDA $C02F
>>  STX $CD
>>  STA $CC
>>  LDA $4E
>>  LDX $4F
>>  STA $CB
>>  STX $C9
>> ...
>> 
>> 
>> test to see if your computer's VBL or HBL gives values with this:
>> 
>> 300: LDX $C02E
>>  LDA $C02F
>>  JSR $F941
>>  BIT $C000
>>  BPL $300
>>  BIT $C010
>>  RTS
>> 
>
> When you seed a random number generator you are only selecting a point in
> the generators cycle where you want to start. 
>
> A good generator will have a very long cycle, but every generator has at
> least one cycle, and a good generator has only one, maximal length cycle.  
>
> So if you have a two-byte seed, you are randomly selecting one of 2^16
> starting points in the cycle. A longer seed does not make the numbers more
> random, it just selects from a larger number of starting points. The
> quality of a PRNG is not determined by its seed, but only by its algorithm.
>
>
> I'd guess that 2^16 different sequences of pseudorandom numbers is more
> than enough for any application. 
>
> In the case of Applesoft's RND generator, it is so riddled with short
> cycles that seeding with a random (and therefore untested) seed has a high
> probability of producing a short, degenerate sequence. Better to select
> from a small set of seeds that have been verified to generate at least a
> few thousand different numbers. 
>
> Of course, it's actually best to avoid RND entirely for any serious work. 

I used a high-quality linear congruential generator in my 3D tic-tac-toe
program.  I was just going to say something about it, and I found this
URL in my program comments:

http://www.6502.org/source/integers/random/random.html

Scott
-- 
Scott Hemphill	hemphill@alumni.caltech.edu
"This isn't flying.  This is falling, with style."  -- Buzz Lightyear

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