Name: Title:

 Name:
ONLINE COMPILERS
LIBRARY
MANUAL PAGES & DOCS
CONTACT

User Submitted Source Code!

Description:
Doors
Language: FORTRAN
Code:
program Doors

implicit none

real*8 p1,p2,p3

integer iCase,numCases
integer num1,num2,num3
integer,allocatable :: i1(:),i2(:),i3(:)
real,allocatable :: randNumbers(:)

numCases=100

! Set up the variable spaces
allocate(i1(numCases))
allocate(i2(numCases))
allocate(i3(numCases))
allocate(randNumbers(numCases))

! Zero the values
do iCase=1,numCases
i1(iCase)=0
i2(iCase)=0
i3(iCase)=0
end do

! Get random numbers
CALL init_random_seed()
CALL RANDOM_NUMBER(randNumbers)

! Define the values for each door
do iCase=1,numCases

if(randNumbers(iCase) .le. 0.3333)i1(iCase)=1
if(randNumbers(iCase) .gt. 0.3333 .and. randNumbers(iCase) .le. 0.6666)i2(iCase)=1
if(randNumbers(iCase) .gt. 0.6666)i3(iCase)=1
end do

! Test the random numbers
num1=0
num2=0
num3=0
do iCase=1,numCases
num1=num1+i1(iCase)
num2=num2+i2(iCase)
num3=num3+i3(iCase)
end do

print(*,*)numCases,num1,num2,num3

end program Doors

SUBROUTINE init_random_seed()
INTEGER :: i, n, clock
INTEGER, DIMENSION(:), ALLOCATABLE :: seed

CALL RANDOM_SEED(size = n)
ALLOCATE(seed(n))

CALL SYSTEM_CLOCK(COUNT=clock)

seed = clock + 37 * (/ (i - 1, i = 1, n) /)
CALL RANDOM_SEED(PUT = seed)

DEALLOCATE(seed)
END SUBROUTINE