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

Re: Interesting one-line BASIC program



Michael J. Mahon wrote:
sicklittlemonkey wrote:

On Apr 1, 2:45 am, "Michael J. Mahon" <mjma...@aol.com> wrote:

As you'll see if you Ctl-C out of the loop and examine "I" when
the display stops changing, it takes less than 20000 iterations.



Or one can count it exactly below - emulator recommended! ;-)

10 HGR
20 FOR I = 1 TO 40000
30 OFFSET = 8192 + 8192 * RND(1)
40 IF PEEK(OFFSET) = 0 THEN PERIOD = I
50 POKE OFFSET, 255
60 REM OR TO VISUALISE ENTROPY USE ...
70 REM POKE OFFSET, PEEK(OFFSET) + 1
80 NEXT I
90 PRINT PERIOD

The period seems to be around 38,000 depending on the seed.
(The large variation is strange - I'd pry if I had time.)

Oh, I came across this quite a while back, and again now:
A Better Random Number Generator for Apple's Floating Point BASIC
http://www.kaner.com/pdfs/random.pdf


I've written to him for the full paper, including implementation.

There have been several such papers published over the years,
including at least one in Call-A.P.P.L.E.

One well-known problem with RND is the incomplete seeding at
coldstart time, but apparently it's bad regardless of seeding...

I wonder how many Monte Carlo simulations on Apples have
been tainted by this bug?  ;-)

BTW, after seeding with RND(-12345) I found a "period" of 63,803
(after the first run!!) using a byte vector of $6000 bytes, and
a "period" of 63,877 using a *bit* vector of $30000 bits.

It's evident that we are only measuring the periodicity of the
high bits of the number, and the low bits are still moving around
in some "strange attractor" orbit.

-michael

NadaPong: Network game demo for Apple II computers!
Home page:  http://members.aol.com/MJMahon/

"The wastebasket is our most important design
tool--and it's seriously underused."