Next: Interfaces
Up: Random Number Generation
Previous: Random Number Generation
PROGRAM test
IMPLICIT NONE
INTEGER throw_dice,th
DO I = 1,100
th = throw_dice()
PRINT*, 'total throw= ', th
END DO
END PROGRAM
FUNCTION throw_dice()
IMPLICIT NONE
INTEGER :: throw_dice
INTEGER :: throw1,throw2
CALL RANDOM_NUMBER(r)
! r is returned 0 <= r <= 1
! NINT(r*5) gives an integer between 0 and 5
throw1 = 1 + NINT(r*5)
PRINT*, 'throw1= ', throw1
CALL RANDOM_NUMBER(r)
throw2 = 1 + NINT(r*5)
PRINT*, 'throw2= ', throw2
throw_dice = throw1 + throw2
END FUNCTION
Next: Interfaces
Up: Random Number Generation
Previous: Random Number Generation
©University of Liverpool, 1997
Thu May 29 10:11:26 BST 1997Not for commercial use.