| 1 |
! { dg-do compile } |
| 2 |
! { dg-require-visibility "" } |
| 3 |
|
| 4 |
module general_rand |
| 5 |
implicit none |
| 6 |
private |
| 7 |
|
| 8 |
integer, public, parameter :: GNDP = kind(1.0d0) |
| 9 |
|
| 10 |
real(kind = GNDP), save :: & |
| 11 |
gnc = 362436.0 / 16777216.0, & |
| 12 |
gncd = 7654321.0 / 16777216.0, & |
| 13 |
gncm = 16777213.0 / 16777216.0 |
| 14 |
integer, save :: & |
| 15 |
gni97 = 97, & |
| 16 |
gnj97 = 33 |
| 17 |
|
| 18 |
real(kind = GNDP), save :: gnu(97) |
| 19 |
|
| 20 |
contains |
| 21 |
subroutine gn_fatal(message) |
| 22 |
character(len = *), intent(in) :: message |
| 23 |
|
| 24 |
stop 1 |
| 25 |
end subroutine gn_fatal |
| 26 |
|
| 27 |
function gn_monte_rand(min, max) result(monte) |
| 28 |
real(kind = GNDP), intent(in) :: min |
| 29 |
real(kind = GNDP), intent(in) :: max |
| 30 |
real(kind = GNDP) :: monte |
| 31 |
|
| 32 |
real :: monte_temp |
| 33 |
|
| 34 |
if (min > max) then |
| 35 |
call gn_fatal('gn_monte_rand: min > max') |
| 36 |
else if (min == max) then |
| 37 |
call gn_fatal('gn_monte_rand: min = max: returning min') |
| 38 |
monte_temp = min |
| 39 |
else |
| 40 |
|
| 41 |
monte_temp = gnu(gni97) - gnu(gnj97) |
| 42 |
if (monte_temp < 0.0) then |
| 43 |
monte_temp = monte_temp + 1.0 |
| 44 |
end if |
| 45 |
|
| 46 |
gnu(gni97) = monte_temp |
| 47 |
gni97 = gni97 - 1 |
| 48 |
if (gni97 == 0) then |
| 49 |
gni97 = 97 |
| 50 |
end if |
| 51 |
end if |
| 52 |
|
| 53 |
monte = min + monte_temp * (max - min) |
| 54 |
|
| 55 |
end function gn_monte_rand |
| 56 |
|
| 57 |
end module general_rand |