RANDOMS.I

[Table of Contents]

The RANDOMS.I include file resides on the Kyan Pascal 2.x Utilities Disk 1.


  • PROCEDURE SEED(NUM1,NUM2,NUM3,NUM4:INTEGER);
  • FUNCTION RND:REAL;
  • FUNCTION RANDOM(MIN,MAX:INTEGER):INTEGER;


For more information, see the Random Numbers page.

Source Code


PROCEDURE SEED(NUM1,NUM2,NUM3,NUM4:INTEGER);
BEGIN
#A
 LDY #5
SEED1 LDA (_SP),Y
 STA POLYN-5,Y
 INY
 CPY #12
 BNE SEED1
 ORA #1
 STA GEN+7
#
END;

FUNCTION RND:REAL;
BEGIN
RND:=0;
#A
 TXA
 PHA
 LDA #0
 STA _T
RAN1 INC _T
 JSR POLY
 CMP #0
 BEQ RAN1
 ORA #$10
 LDY #5
 STA (_SP),Y
;
RAN2 INY
 JSR POLY
 ROL
 ROL
 ROL
 ROL
 AND #$F0
 STA _T+1
 JSR POLY
 ORA _T+1
 STA (_SP),Y
 CPY #11
 BCC RAN2
 LDA _T
 INY
 STA (_SP),Y
 PLA
 TAX
#
END;
#A
POLY TYA
 PHA
 LDY #0
POLY1 INY
 CLC
 ROL POLYN
 ROL POLYN+1
 ROL POLYN+2
 ROL POLYN+3
 ROL POLYN+4
 ROL POLYN+5
 ROL POLYN+6
 ROL POLYN+7
 BCC POLY3
;
 LDX #0
POLY2 LDA POLYN,X
 EOR GEN,X
 STA POLYN,X
 INX
 CPX #8
 BCC POLY2
 SEC
;
POLY3 ROL _T+2
 CPY #4
 BCC POLY1
;
 PLA
 TAY
 LDA _T+2
 AND #$0F
 CMP #$0A
 BCS POLY
 RTS
;
GEN DB $A1
 DB $A2
 DB $1A
 DB $A2
 DB $91
 DB $C3
 DB $93
 DB $C0
;
POLYN DB $63
 DB $42
 DB $A1
 DB $23
 DB $55
 DB $09
 DB $03
 DB $87
#

FUNCTION RANDOM(MIN,MAX:INTEGER):INTEGER;
BEGIN
   RANDOM := MIN + TRUNC(RND*(MAX-MIN+1))
END;

FUNCTION Random_Byte: Integer;
    BEGIN
        RANDOM_BYTE:=0;
#A
  LDA $D20A    ;get RANDOM (53770)
  LDY #5       ;offset to ISO_Var
  STA (_SP), Y ;...store it
#
END;(* Random Byte function *)

No comments:

Post a Comment