Last change
on this file since 718 was
484,
checked in by raasch, 15 years ago
|
typo in file headers removed
|
-
Property svn:keywords set to
Id
|
File size:
1.6 KB
|
Rev | Line | |
---|
[1] | 1 | FUNCTION random_gauss( idum, upper_limit ) |
---|
| 2 | |
---|
| 3 | !------------------------------------------------------------------------------! |
---|
[484] | 4 | ! Current revisions: |
---|
[1] | 5 | ! ----------------- |
---|
| 6 | ! |
---|
| 7 | ! |
---|
| 8 | ! Former revisions: |
---|
| 9 | ! ----------------- |
---|
[3] | 10 | ! $Id: random_gauss.f90 484 2010-02-05 07:36:54Z gryschka $ |
---|
| 11 | ! RCS Log replace by Id keyword, revision history cleaned up |
---|
| 12 | ! |
---|
[1] | 13 | ! Revision 1.4 2006/08/04 15:01:48 raasch |
---|
| 14 | ! Range of random number is limited by an upper limit (new second parameter) |
---|
| 15 | ! |
---|
| 16 | ! Revision 1.1 1998/03/25 20:09:47 raasch |
---|
| 17 | ! Initial revision |
---|
| 18 | ! |
---|
| 19 | ! |
---|
| 20 | ! Description: |
---|
| 21 | ! ------------ |
---|
| 22 | ! Generates a gaussian distributed random number (mean value 1, sigma = 1) |
---|
| 23 | ! This routine is taken from the "numerical recipies". |
---|
| 24 | !------------------------------------------------------------------------------! |
---|
| 25 | |
---|
| 26 | USE random_function_mod |
---|
| 27 | |
---|
| 28 | IMPLICIT NONE |
---|
| 29 | |
---|
| 30 | INTEGER :: idum, iset |
---|
| 31 | REAL :: fac, gset, random_gauss, rsq, upper_limit, v1, v2 |
---|
| 32 | |
---|
| 33 | SAVE iset, gset |
---|
| 34 | |
---|
| 35 | DATA iset /0/ |
---|
| 36 | |
---|
| 37 | ! |
---|
| 38 | !-- Random numbers are created as long as they do not fall below the given |
---|
| 39 | !-- upper limit |
---|
| 40 | DO |
---|
| 41 | |
---|
| 42 | IF ( iset == 0 ) THEN |
---|
| 43 | rsq = 0.0 |
---|
| 44 | DO WHILE ( rsq >= 1.0 .OR. rsq == 0.0 ) |
---|
| 45 | v1 = 2.0 * random_function( idum ) - 1.0 |
---|
| 46 | v2 = 2.0 * random_function( idum ) - 1.0 |
---|
| 47 | rsq = v1**2 + v2**2 |
---|
| 48 | ENDDO |
---|
| 49 | fac = SQRT( -2.0 * LOG( rsq ) / rsq ) |
---|
| 50 | gset = v1 * fac |
---|
| 51 | random_gauss = v2 * fac + 1.0 |
---|
| 52 | iset = 1 |
---|
| 53 | ELSE |
---|
| 54 | random_gauss = gset + 1.0 |
---|
| 55 | iset = 0 |
---|
| 56 | ENDIF |
---|
| 57 | |
---|
| 58 | IF ( ABS( random_gauss - 1.0 ) <= upper_limit ) EXIT |
---|
| 59 | |
---|
| 60 | ENDDO |
---|
| 61 | |
---|
| 62 | END FUNCTION random_gauss |
---|
Note: See
TracBrowser
for help on using the repository browser.