-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrandom1.f
More file actions
54 lines (46 loc) · 1.32 KB
/
random1.f
File metadata and controls
54 lines (46 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
c ----------------------------
function Ran1 ( idum )
c Random number generator, From numerical recipes
integer idum, ia, im, iq, ir, ntab, ndiv
real ran1, am, eps, rnmx
parameter (ia=16807, im=2147483647, am=1./im,iq=127773,ir=2836,
1 ntab=32,ndiv=1+(im-1)/ntab,eps=1.2e-7,rnmx=1.-eps)
integer j, k, iv(ntab), iy
save iv, iy
data iv /ntab*0/, iy /0/
if (idum .le. 0 .or. iy .eq. 0 ) then
idum=max(-idum,1)
do j=ntab+8,1,-1
k=idum/iq
idum=ia*(idum-k*iq)-ir*k
if( idum .lt. 0) idum=idum+im
if (j .le. ntab) iv(j)=idum
enddo
iy = iv(1)
endif
k = idum/iq
idum=ia*(idum-k*iq) - ir*k
if ( idum .lt. 0 ) idum = idum + im
j = 1 + iy/ndiv
iy = iv(j)
iv (j) = idum
ran1 = min(am*iy,rnmx)
return
end
c ----------------------------
subroutine GetRandom1 ( iseed, n, wt, i1, iSave, n1 )
integer iseed,i1,isave,n1,n
real wt(n1, 1)
real x
c Get random number
x = ran1( iseed )
do i=1,n
if ( x .le. wt(i1,i) ) then
iSave = i
return
endif
enddo
write (*,*) ' Get Random Number 1'
write (*,'( 2x,''Error - bad ran number or weights'')')
stop 99
end