1 SUBROUTINE RANMAR(RVEC,LENV)
2 C ----------------------------------------------------------------------
3 C<<<<<FUNCTION RANMAR(IDUMM)
4 C CERNLIB V113, VERSION WITH AUTOMATIC DEFAULT INITIALIZATION
5 C Transformed to SUBROUTINE to be as in CERNLIB
6 C AM.Lutz November 1988, Feb. 1989
8 C!Universal random number generator proposed by Marsaglia and Zaman
9 C in report FSU-SCRI-87-50
10 C modified by F. James, 1988 and 1989, to generate a vector
11 C of pseudorandom numbers RVEC of length LENV, and to put in
12 C the COMMON block everything needed to specify currrent state,
13 C and to add input and output entry points RMARIN, RMARUT.
15 C Unique random number used in the program
16 C ----------------------------------------------------------------------
17 COMMON / INOUT / INUT,IOUT
19 COMMON/RASET1/U(97),C,I97,J97
20 PARAMETER (MODCNS=1000000000)
21 DATA NTOT,NTOT2,IJKL/-1,0,0/
23 IF (NTOT .GE. 0) GO TO 50
25 C Default initialization. User has called RANMAR without RMARIN.
32 ENTRY RMARIN(IJKLIN, NTOTIN,NTOT2N)
33 C Initializing routine for RANMAR, may be called before
34 C generating pseudorandom numbers with RANMAR. The input
35 C values should be in the ranges: 0<=IJKLIN<=900 OOO OOO
36 C 0<=NTOTIN<=999 999 999
37 C 0<=NTOT2N<<999 999 999!
38 C To get the standard values in Marsaglia-s paper, IJKLIN=54217137
44 C always come here to initialize
48 I = MOD(IJ/177, 177) + 2
50 K = MOD(KL/169, 178) + 1
52 WRITE(IOUT,201) IJKL,NTOT,NTOT2
53 201 FORMAT(1X,' RANMAR INITIALIZED: ',I10,2X,2I10)
58 M = MOD(MOD(I*J,179)*K, 179)
63 IF (MOD(L*M,64) .GE. 32) S = S+T
74 C Complete initialization by skipping
75 C (NTOT2*MODCNS + NTOT) random numbers
76 DO 45 LOOP2= 1, NTOT2+1
78 IF (LOOP2 .EQ. NTOT2+1) NOW=NTOT
80 WRITE (IOUT,'(A,I15)') ' RMARIN SKIPPING OVER ',NOW
83 IF (UNI .LT. 0.) UNI=UNI+1.
86 IF (I97 .EQ. 0) I97=97
88 IF (J97 .EQ. 0) J97=97
94 IF (KALLED .EQ. 1) RETURN
96 C Normal entry to generate LENV random numbers
100 IF (UNI .LT. 0.) UNI=UNI+1.
103 IF (I97 .EQ. 0) I97=97
105 IF (J97 .EQ. 0) J97=97
107 IF (C .LT. 0.) C=C+CM
109 IF (UNI .LT. 0.) UNI=UNI+1.
110 C Replace exact zeroes by uniform distr. *2**-24
111 IF (UNI .EQ. 0.) THEN
113 C An exact zero here is very unlikely, but lets be safe.
114 IF (UNI .EQ. 0.) UNI= TWOM24*TWOM24
119 IF (NTOT .GE. MODCNS) THEN
124 C Entry to output current status
125 ENTRY RMARUT(IJKLUT,NTOTUT,NTOT2T)