lundi 18 avril 2016

No output results

I wrote a FORTRAN code to generate a series of random number. In this code, I could set up random number window (minimum and maximum random number) and percentage of random number within this window (number of random number). I want that the generated random numbers are always different from each other.

I could use GFORTRAN compiler to compile it successfully; however, I do not have random number generated when I ran the code. For example, when I input my minimum value 21 and maximum value 85 and percentage of random number: 0.31, I only got 19 (this is the total number of random numbers within this window.) and nothing else. I paste my code below.

Would you anyone give me some suggestions on my problem? Thank you very much in advance.

   PROGRAM RANDOM_POSITION
   IMPLICIT NONE
   REAL percent, val
   INTEGER maxi, mini, num, i, l
   INTEGER, DIMENSION(1), ALLOCATABLE :: position(:)
   PRINT *,'Range for the impurity position(maximum and minimum value):'
   PRINT *,'Minimum value:'
   READ (UNIT=*, FMT=*) mini
   PRINT *,'Maximum value:'
   READ (UNIT=*, FMT=*) maxi
   PRINT 11,'Percentage of impurity='
   11 FORMAT(A23,$)
   READ (UNIT=*, FMT=*) percent
   num = (maxi-mini)*percent
   PRINT *, num
   ALLOCATE (position(num))
   CALL RANDOM_SEED()
   DO i=1, num ,1
      CALL RANDOM_NUMBER(val)
      position(i) = mini + val*num
      CALL JUDGEMENT(position, i)
      l = 0
      DO WHILE (l .EQ. 0)
               position(i) = mini + val*num
               CALL JUDGEMENT(position, i)
      END DO      
   PRINT *, position(i)
   END DO
   DEALLOCATE(position)
   STOP
   END PROGRAM RANDOM_POSITION
   SUBROUTINE JUDGEMENT(arr, j)
   IMPLICIT NONE
   INTEGER j, k, l
   INTEGER, DIMENSION(1) :: arr(j)
   l = 1
   DO k=1, j-1, 1
      IF (arr(k) .EQ. arr(j)) THEN
         l = 0
         EXIT
      ELSE
         l = 1
      END IF
   END DO
   RETURN
   END SUBROUTINE JUDGEMENT




Aucun commentaire:

Enregistrer un commentaire