COSMOS v7.655  COSMOSv7655
(AirShowerMC)
kbinom.f
Go to the documentation of this file.
1 ! test kbinom
2 ! implicit none
3 ! real*8 p
4 ! integer n0, i, n
5 ! p=.45
6 ! n0=30
7 ! do i=1, 10000
8 ! call kbinom(p, n0, n)
9 ! write(*, *) n
10 ! enddo
11 ! end
12 ! ************************************************************
13 ! *
14 ! * kbinom: samples binomial random #
15 ! *
16 ! ************************ tested 88.08.26 ***********k.k*****
17 !
18 ! prob(nb)=comb(n,nb)*p**nb * (1.-p)**(n-nb)
19 !
20 ! /usage/ call kbinom(p, n, nb)
21 ! p: input. (0, 1)
22 ! n: input. >0 integer
23 ! nb: output. sampled #
24 !
25  subroutine kbinom(p, n, nb)
26  implicit none
27  real*8 p
28  integer n, nb
29 
30  real*8 av, s, x, u
31  integer i
32 !
33  nb=0
34  if(n .gt. 20 .and. p .gt. .25 .and. p .lt. .75) then
35  av=p*n
36  s=sqrt(p*n*(1.-p))
37 ! *** until loop***
38  do while (.true.)
39  call kgauss(av, s, x)
40  nb=x+.5
41  if(nb .ge. 0 .and. nb .le. n) goto 100
42  enddo
43  100 continue
44  else
45  do i=1, n
46  call rndc(u)
47  if(u .le. p) then
48  nb=nb+1
49  endif
50  enddo
51  endif
52  end
subroutine kbinom(p, n, nb)
Definition: kbinom.f:26
block data cblkElemag data *AnihiE ! Eposi< 1 TeV, anihilation considered *X0/365.667/, ! radiation length of air in kg/m2 *Ecrit/81.e-3/, ! critical energy of air in GeV *MaxComptonE/1./, ! compton is considered below 1 GeV *MaxPhotoE/1.e-3/, ! above this, PhotoElectric effect neg. *MinPhotoProdE/153.e-3/, ! below 153 MeV, no gp --> hadrons ! scattering const not MeV *Knockon true
Definition: cblkElemag.h:7
subroutine rndc(u)
Definition: rnd.f:91
subroutine kgauss(m, v, g1)
Definition: kgauss.f:10