StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
tauola-random.h
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
7 C
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.
14 C
15 C Unique random number used in the program
16 C ----------------------------------------------------------------------
17  COMMON / INOUT / INUT,IOUT
18  DIMENSION RVEC(*)
19  COMMON/RASET1/U(97),C,I97,J97
20  PARAMETER (MODCNS=1000000000)
21  DATA NTOT,NTOT2,IJKL/-1,0,0/
22 C
23  IF (NTOT .GE. 0) GO TO 50
24 C
25 C Default initialization. User has called RANMAR without RMARIN.
26  IJKL = 54217137
27  NTOT = 0
28  NTOT2 = 0
29  KALLED = 0
30  GO TO 1
31 C
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
39 C NTOTIN,NTOT2N=0
40  IJKL = IJKLIN
41  NTOT = MAX(NTOTIN,0)
42  NTOT2= MAX(NTOT2N,0)
43  KALLED = 1
44 C always come here to initialize
45  1 CONTINUE
46  IJ = IJKL/30082
47  KL = IJKL - 30082*IJ
48  I = MOD(IJ/177, 177) + 2
49  J = MOD(IJ, 177) + 2
50  K = MOD(KL/169, 178) + 1
51  L = MOD(KL, 169)
52  WRITE(IOUT,201) IJKL,NTOT,NTOT2
53  201 FORMAT(1X,' RANMAR INITIALIZED: ',I10,2X,2I10)
54  DO 2 II= 1, 97
55  S = 0.
56  T = .5
57  DO 3 JJ= 1, 24
58  M = MOD(MOD(I*J,179)*K, 179)
59  I = J
60  J = K
61  K = M
62  L = MOD(53*L+1, 169)
63  IF (MOD(L*M,64) .GE. 32) S = S+T
64  3 T = 0.5*T
65  2 U(II) = S
66  TWOM24 = 1.0
67  DO 4 I24= 1, 24
68  4 TWOM24 = 0.5*TWOM24
69  C = 362436.*TWOM24
70  CD = 7654321.*TWOM24
71  CM = 16777213.*TWOM24
72  I97 = 97
73  J97 = 33
74 C Complete initialization by skipping
75 C (NTOT2*MODCNS + NTOT) random numbers
76  DO 45 LOOP2= 1, NTOT2+1
77  NOW = MODCNS
78  IF (LOOP2 .EQ. NTOT2+1) NOW=NTOT
79  IF (NOW .GT. 0) THEN
80  WRITE (IOUT,'(A,I15)') ' RMARIN SKIPPING OVER ',NOW
81  DO 40 IDUM = 1, NTOT
82  UNI = U(I97)-U(J97)
83  IF (UNI .LT. 0.) UNI=UNI+1.
84  U(I97) = UNI
85  I97 = I97-1
86  IF (I97 .EQ. 0) I97=97
87  J97 = J97-1
88  IF (J97 .EQ. 0) J97=97
89  C = C - CD
90  IF (C .LT. 0.) C=C+CM
91  40 CONTINUE
92  ENDIF
93  45 CONTINUE
94  IF (KALLED .EQ. 1) RETURN
95 C
96 C Normal entry to generate LENV random numbers
97  50 CONTINUE
98  DO 100 IVEC= 1, LENV
99  UNI = U(I97)-U(J97)
100  IF (UNI .LT. 0.) UNI=UNI+1.
101  U(I97) = UNI
102  I97 = I97-1
103  IF (I97 .EQ. 0) I97=97
104  J97 = J97-1
105  IF (J97 .EQ. 0) J97=97
106  C = C - CD
107  IF (C .LT. 0.) C=C+CM
108  UNI = UNI-C
109  IF (UNI .LT. 0.) UNI=UNI+1.
110 C Replace exact zeroes by uniform distr. *2**-24
111  IF (UNI .EQ. 0.) THEN
112  UNI = TWOM24*U(2)
113 C An exact zero here is very unlikely, but lets be safe.
114  IF (UNI .EQ. 0.) UNI= TWOM24*TWOM24
115  ENDIF
116  RVEC(IVEC) = UNI
117  100 CONTINUE
118  NTOT = NTOT + LENV
119  IF (NTOT .GE. MODCNS) THEN
120  NTOT2 = NTOT2 + 1
121  NTOT = NTOT - MODCNS
122  ENDIF
123  RETURN
124 C Entry to output current status
125  ENTRY RMARUT(IJKLUT,NTOTUT,NTOT2T)
126  IJKLUT = IJKL
127  NTOTUT = NTOT
128  NTOT2T = NTOT2
129  RETURN
130  END