Hi, I am making a program that generates random numbers between 0 and 1, and then displays the number of randoms in each appropriate bin (the bin sizes are 0.05).
I'm thinking that I would use something like "bin1 ++" to add a count to the bin, but I'm not sure. My code is below. I am using FORTRAN 77.
Thanks for your help!
Code:
PROGRAM random_number
!** program to test a random number generator
IMPLICIT NONE
INTEGER :: seed, a
INTEGER :: bin1, bin2, bin3, bin4, bin5, bin6, bin7, bin8, bin9, bin10, bin11, bin12, bin13, bin14, bin15, bin16,
& bin17, bin18, bin19, bin20
PARAMETER (seed = 86456)
REAL :: x, rand
CALL SRAND(seed)
DO a=1, 20000
x = rand(a) !*** assigns number between 0 and 1 to variable X
IF (x > 0 .AND. x <= 0.05) THEN
!**add one count to bin1
ELSEIF (x > 0.05 .AND. x <= 0.10) THEN
!**add one count to bin2
ELSEIF (x > 0.10 .AND. x <= 0.15) THEN
!**add one count to bin3
ELSEIF (x > 0.15 .AND. x <= 0.20) THEN
!**add one count to bin4
ELSEIF (x > 0.20 .AND. x <= 0.25) THEN
!**add one count to bin5
ELSEIF (x > 0.25 .AND. x <= 0.30) THEN
!**add one count to bin6
ELSEIF (x > 0.30 .AND. x <= 0.35) THEN
!**add one count to bin7
ELSEIF (x > 0.35 .AND. x <= 0.40) THEN
!**add one count to bin8
ELSEIF (x > 0.40 .AND. x <= 0.45) THEN
!**add one count to bin9
ELSEIF (x > 0.45 .AND. x <= 0.50) THEN
!**add one count to bin10
ELSEIF (x > 0.50 .AND. x <= 0.55) THEN
!**add one count to bin11
ELSEIF (x > 0.55 .AND. x <= 0.60) THEN
!**add one count to bin12
ELSEIF (x > 0.60 .AND. x <= 0.65) THEN
!**add one count to bin13
ELSEIF (x > 0.65 .AND. x <= 0.70) THEN
!**add one count to bin14
ELSEIF (x > 0.70 .AND. x <= 0.75) THEN
!**add one count to bin15
ELSEIF (x > 0.75 .AND. x <= 0.80) THEN
!**add one count to bin16
ELSEIF (x > 0.80 .AND. x <= 0.85) THEN
!**add one count to bin17
ELSEIF (x > 0.85 .AND. x <= 0.90) THEN
!**add one count to bin18
ELSEIF (x > 0.90 .AND. x <= 0.95) THEN
!**add one count to bin19
ELSEIF (x > 0.95 .AND. x <= 1.00) THEN
!**add one count to bin20
ENDIF
WRITE(*,*) bin1, bin2, bin3, bin4, bin5, bin6, bin7, bin8, bin9, bin10, bin11, bin12, bin13, bin14, bin15,
& bin16, bin17, bin18, bin19, bin20
END DO
END PROGRAM random_number