source: palm/trunk/SOURCE/random_function.f90 @ 1

Last change on this file since 1 was 1, checked in by raasch, 17 years ago

Initial repository layout and content

File size: 2.2 KB
RevLine 
[1]1 MODULE random_function_mod
2!-------------------------------------------------------------------------------!
3! Actual revisions:
4! -----------------
5!
6!
7! Former revisions:
8! -----------------
9! $Log: random_function.f90,v $
10! Revision 1.3  2003/10/29 09:06:57  raasch
11! Former function changed to a module.
12!
13! Revision 1.2  2001/01/22 08:00:23  raasch
14! Comments translated into English
15!
16! Revision 1.1  1998/02/04 16:09:45  raasch
17! Initial revision
18!
19!
20! Description:
21! ------------
22! Random number generator, produces numbers equally distributed in interval [0,1]
23! This routine is taken from the "numerical recipies"
24!-------------------------------------------------------------------------------!
25
26    IMPLICIT NONE
27
28    PRIVATE
29
30    PUBLIC random_function, random_function_ini
31
32    INTEGER, PUBLIC, SAVE ::  random_iv(32), random_iy
33
34    INTERFACE random_function_ini
35       MODULE PROCEDURE random_function_ini
36    END INTERFACE random_function_ini
37
38    INTERFACE random_function
39       MODULE PROCEDURE random_function
40    END INTERFACE random_function
41
42 CONTAINS
43
44    SUBROUTINE random_function_ini
45
46       IMPLICIT NONE
47
48       random_iv = 0
49       random_iy = 0
50
51    END SUBROUTINE random_function_ini
52
53    FUNCTION random_function( idum )
54
55
56       IMPLICIT NONE
57
58       INTEGER ::  ia, idum, im, iq, ir, ndiv, ntab
59       REAL    ::  am, eps, random_function, ranf, rnmx
60
61       PARAMETER ( ia=16807, im=2147483647, am=1.0/im, iq=127773, ir=2836, &
62                   ntab=32, ndiv=1+(im-1)/ntab, eps=1.2e-7, rnmx=1.0-eps )
63
64       INTEGER ::  j, k
65
66
67       IF ( idum .le. 0  .or.  random_iy .eq. 0 )  THEN
68          idum = max (-idum,1)
69          DO  j = ntab+8,1,-1
70             k    = idum / iq
71             idum = ia * ( idum - k * iq ) - ir * k
72             IF ( idum .lt. 0 )  idum = idum + im
73             IF ( j .le. ntab )  random_iv(j) = idum
74          ENDDO
75          random_iy = random_iv(1)
76       ENDIF
77
78       k    = idum / iq
79       idum = ia * ( idum - k * iq ) - ir * k
80       IF ( idum .lt. 0 )  idum = idum + im
81       j            = 1 + random_iy / ndiv
82       random_iy    = random_iv(j)
83       random_iv(j) = idum
84       random_function  = min ( am * random_iy , rnmx )
85
86    END FUNCTION random_function
87
88 END MODULE random_function_mod
Note: See TracBrowser for help on using the repository browser.