forked from lynch829/Monte-Carlo-Radiation-Transport-code
-
Notifications
You must be signed in to change notification settings - Fork 0
/
search.f
28 lines (20 loc) · 725 Bytes
/
search.f
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
subroutine search(cnt,cdf,nlow,ran,iseed)
implicit none
integer nup,nlow,cnt,middle,iseed
real ran,ran2
real cdf(cnt-1)
c search by bisection algorithm. finds bracketing indice nlow and nlow+1 that bracket a random number in the cdf
nup = cnt
nlow = 1
middle = int((nup+nlow)/2.)
ran = ran2(iseed)
do while((nup - nlow) .gt. 1)
middle = int((nup+nlow)/2.)
if (ran .gt. cdf(middle)) then
nlow = middle
else
nup = middle
end if
end do
return
end