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