Annotation of imach/src/random.alw, revision 1.1
1.1 ! brouard 1: COMMENT: RANDOM NUMBER GENERATOR
! 2: ***********************
! 3:
! 4: PROCEDURE RANDOM RETURNS A LONG REAL RANDOM NUMBER UNIFORMLY
! 5: DISTRIBUTED IN (0,1) (INCLUDING 0 BUT NOT 1),
! 6: RANINIT(R) WITH R ANY INTEGER MUST BE CALLED FOR
! 7: INITIALIZATION BEFORE THE FIRST CALL TO RANDOM, AND THE
! 8: DECLARATIONS OF RAN1, RAN2 AND RAN3 MUST BE GLOBAL,
! 9: THE ALGORITHM RETURNS X(N)/2**56, WHERE
! 10: X(N) = X(N-1) + X(N-127) (MOO 2**56),
! 11: SINCE 1 + X + X**127 IS PRIMITIVE (MOD 2), THE PERIOD IS AT
! 12: LEAST 2**127 - 1 > 10**38, SEE KNUTH (1969), PP. 26, 34, 464,
! 13: X(N) IS STORED IN A LONG REAL WORD AS
! 14: RAN3 = X(N)/2**56 - 1/2, AND ALL FLOATING POINT ARITHMETIC
! 15: IS EXACT;
! 16:
! 17: LONG REAL PROCEDURE RANDOM(INTEGER VALUE NAUGHT);
! 18: BEGIN
! 19: LONG REAL RAN1; INTEGER RAN2; LONG REAL ARRAY RAN3 (0::126);
! 20: INTEGER R; LOGICAL INIT;
! 21: INIT := FALSE;
! 22: IF INIT THEN GO TO L3;
! 23: R := ABS(NAUGHT) REM 8190 + 1;
! 24: RAN2 := 127; WHILE RAN2 > 0 DO
! 25: BEGIN RAN2 := RAN2 - 1; RAN1 := -2L**55;
! 26: FOR I := 1 UNTIL 7 DO
! 27: BEGIN R := (1756*R) REM 8191;
! 28: RAN1 := (RAN1 + (R DIV 32) )*( 1/256) ;
! 29: END;
! 30: RAN3 (RAN2) := RAN1
! 31: END;
! 32: INIT := TRUE;
! 33: L3: RAN2 := IF RAN2 = 0 THEN 126 ELSE RAN2 - 1;
! 34: RAN1 := RAN1 + RAN3 (RAN2);
! 35: RAN3 (RAN2) := RAN1 := IF RAN1 < 0L THEN RAN1 + 0.5L
! 36: ELSE RAN1 - 0.5L;
! 37: RAN1 + 0.5L
! 38: END RANDOM.
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>