Analysis Software
Documentation for sPHENIX simulation 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 ! nra 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  endif
65 
66  return
67  end
68 
69 !-----------------------------------------------------------------
70 ! Replace the obsolete CERNLIB RNDM functions
71 
72  real function rndm (dummy)
73 
74  implicit none
75 
76  real dummy, r
77 
78  call ranlux(r,1)
79 
80  rndm = r
81 
82  return
83  end
84 
85 ! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
86  integer function irndm (dummy)
87 
88  implicit none
89 
90  real dummy, r
91  integer i
92 
93  equivalence(r,i)
94 
95  call ranlux(r,1)
96  irndm = i
97 
98  return
99  end
100 
101 !-----------------------------------------------------------------
102 ! Replace the obsolete CERNLIB NRAN subroutine
103 
104  subroutine nran (r,n)
105 
106  implicit none
107 
108  integer n
109  real r(n)
110 
111  call ranlux(r,n)
112 
113  return
114  end
115 
116 !-----------------------------------------------------------------
117 ! Replace the obsolete CERNLIB RANNOR subroutine
118 
119  subroutine rannor (a,b)
120 
121  implicit none
122 
123  real a, b, r(2)
124  external nran
125 
126  call rnormx(r,2,nran)
127  a = r(1)
128  b = r(2)
129 
130  return
131 
132  end
133 
134 !-----------------------------------------------------------------
135 ! Replace the F77 RANF
136 
137  real function ranf (dummy)
138 
139  implicit none
140 
141  real dummy, r
142 
143  call ranlux(r,1)
144 
145  ranf = r
146 
147  return
148  end
149 
150 !-----------------------------------------------------------------
151 ! Replace the JETSET random number generator
152 
153  real function rlu(idummy)
154 
155  implicit none
156 
157  integer idummy
158  real r
159 
160  call ranlux(r,1)
161 
162  rlu = r
163 
164  return
165  end
166 
167 !-----------------------------------------------------------------
168 ! Replace the DIVONNE random number generator
169 
170  subroutine ranums (r,n)
171 
172  implicit none
173 
174  integer n
175  real r(n)
176 
177  call ranlux(r,n)
178 
179  return
180  end
181