EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
gmc_random.f
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file gmc_random.f
1 !-----------------------------------------------------------------
2 ! The point of this set of routines is to replace all potentially
3 ! used random number generators with functions and subroutines
4 ! that utilize a common seed sequence. In this case:
5 !
6 ! the CERNLIB RANLUX series
7 !
8 ! MC programmers should now always use:
9 ! rndmq to initialize or obtain status
10 ! rlu to get a single 0:1 random number
11 ! nran to get a vector of 0:1 random numbers
12 ! rannor to get 2 Gaussian random numbers
13 !
14 ! Documentation on RANLUX can be found here:
15 ! http://wwwinfo.cern.ch/asdoc/shortwrupsdir/v115/top.html
16 !-----------------------------------------------------------------
17 ! Initialization and status retrieval routine for random number sequence
18 !
19 ! CHOPT = ' ' reset sequence NSEQ to the beginning (seeds 0,0)
20 ! 'S' set seeds for sequence NSEQ to given values
21 ! 'G' get the current seeds for the current sequence
22 !
23 ! Note1: If ISEQ.le.0, the current (last used) sequence is used.
24 !-----------------------------------------------------------------
25 
26  subroutine rndmq (nseed1, nseed2, nseq, chopt)
27 
28  implicit none
29 
30  integer lux_level
31  parameter(lux_level=4)
32 
33  integer nseed1, nseed2, nseq
34  integer iseed1, iseed2, iseq, ilux
35  character*(*) chopt
36  character*1 c1opt
37 
38 ! ... force redefined random number generators to be taken from here
39  external rndm, irndm, nran, rannor, ranf, rlu, ranums
40 
41 ! Parse option string
42 
43  c1opt = chopt(1:1)
44  if (c1opt.ne.' '.and.c1opt.ne.'S'.and.c1opt.ne.'G') then
45  write(*,*)('RNDMQ got unrecognized option')
46  stop
47  endif
48 
49 ! Take care of the possibilities of resetting the generator
50 
51 ! ... initialize generator to the beginning (seeds 0,0) of the given sequence
52  if (c1opt.eq.' ') then
53  call rluxgo(lux_level,nseq,0,0)
54 
55 ! ... set seeds to given values, after retrieving current sequence number
56 ! ... (and luxury level, why not)
57  elseif (c1opt.eq.'S') then
58  call rluxat(ilux,iseq,iseed1,iseed2)
59  call rluxgo(ilux,iseq,nseed1,nseed2)
60 
61 ! ... retrieve current seeds and hand them back
62  elseif (c1opt.eq.'G') then
63  call rluxat(ilux,iseq,nseed1,nseed2)
64 
65  endif
66 
67  return
68  end
69 
70 !-----------------------------------------------------------------
71 ! Replace the obsolete CERNLIB RNDM functions
72 
73  real function rndm (dummy)
74 
75  implicit none
76 
77  real dummy, r
78 
79  call ranlux(r,1)
80 
81  rndm = r
82 
83  return
84  end
85 
86 ! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
87  integer function irndm (dummy)
88 
89  implicit none
90 
91  real dummy, r
92  integer i
93 
94  equivalence(r,i)
95 
96  call ranlux(r,1)
97  irndm = i
98 
99  return
100  end
101 
102 !-----------------------------------------------------------------
103 ! Replace the obsolete CERNLIB NRAN subroutine
104 
105  subroutine nran (r,n)
106 
107  implicit none
108 
109  integer n
110  real r(n)
111 
112  call ranlux(r,n)
113 
114  return
115  end
116 
117 !-----------------------------------------------------------------
118 ! Replace the obsolete CERNLIB RANNOR subroutine
119 
120  subroutine rannor (a,b)
121 
122  implicit none
123 
124  real a, b, r(2)
125  external nran
126 
127  call rnormx(r,2,nran)
128  a = r(1)
129  b = r(2)
130 
131  return
132 
133  end
134 
135 !-----------------------------------------------------------------
136 ! Replace the F77 RANF
137 
138  real function ranf (dummy)
139 
140  implicit none
141 
142  real dummy, r
143 
144  call ranlux(r,1)
145 
146  ranf = r
147 
148  return
149  end
150 
151 !-----------------------------------------------------------------
152 ! Replace the JETSET random number generator
153 
154  real function rlu(idummy)
155 
156  implicit none
157 
158  integer idummy
159  real r
160 
161  call ranlux(r,1)
162 
163  rlu = r
164 
165  return
166  end
167 
168 !-----------------------------------------------------------------
169 ! Replace the DIVONNE random number generator
170 
171  subroutine ranums (r,n)
172 
173  implicit none
174 
175  integer n
176  real r(n)
177 
178  call ranlux(r,n)
179 
180  return
181  end
182