[Coco] Example or a replacement for RND

Rietveld Rietveld rietveldh at hotmail.com
Fri May 19 23:55:50 EDT 2017


I don't think I was complaining about the cocos RND command. I just wanted to know if it generated a truly random number every time or followed a lengthy or predictable sequence

Sent from my BlackBerry 10 smartphone.
  Original Message
From: Robert Gault
Sent: Friday, May 19, 2017 11:18 PM
To: CoCoList for Color Computer Enthusiasts
Reply To: CoCoList for Color Computer Enthusiasts
Subject: [Coco] Example or a replacement for RND


It is easy enough to look for "random" number generators in books or on the Internet. Most will
probably be much better than the one in the Basic ROM. So, rather than complaining about what the
Coco has, why not try a replacement.
Below is a random number routine I used for an ml program based on something I read about random
number generators. It is used in an ml graphics program.

RND     EQU     $116    LOCATION OF BASIC RANDOM NUMBER You can seed it with A=RND(-TIMER)

* THIS IS A FAST, HIGH GRADE RANDOM NUMBER GENERATOR
* LENGTH OF NON-REPEATING SEQUENCE = 2,147,483,647
* ENTER: REG.B = N+1 where you want 0<= RND <N
* EXIT:  REG.A = 0 TO 255 or 0 to .99609375
*        after MUL
*        REG.A = 0 to N
*        REG.B = fraction
*        REG.D = 256x(N+.99609375)

RAND    BSR     RND2
        BSR     RND2
        BSR     RND2
        BSR     RND2
        BSR     RND2
        LDA     RND
        MUL
        RTS
RND2    LDA     RND+3   GET 28TH BIT
        ANDA    #%00010000      KEEP 28TH BIT
        LSRA                    00001000 29
        LSRA                    00000100 30
        LSRA                    00000010 31
        EORA    RND+3           KEEP 31ST BIT
        LSRA                    shift
        LSRA                    into carry
        ROR     RND
        ROR     RND+1
        ROR     RND+2
        ROR     RND+3
        RTS

Robert

--
Coco mailing list
Coco at maltedmedia.com
https://pairlist5.pair.net/mailman/listinfo/coco


More information about the Coco mailing list