diff --git a/src/mod_layer.f90 b/src/mod_layer.f90 index 78b6a20a..d2d98f71 100644 --- a/src/mod_layer.f90 +++ b/src/mod_layer.f90 @@ -4,7 +4,7 @@ module mod_layer use mod_activation use mod_kinds, only: ik, rk - use mod_random, only: randn + use nf_random_mod, only: randn implicit none diff --git a/src/mod_random.f90 b/src/mod_random.f90 deleted file mode 100644 index d8c1b4af..00000000 --- a/src/mod_random.f90 +++ /dev/null @@ -1,39 +0,0 @@ -module mod_random - - ! Provides a random number generator with - ! normal distribution, centered on zero. - - use mod_kinds, only: ik, rk - - implicit none - - private - public :: randn - - real(rk), parameter :: pi = 4 * atan(1._rk) - - interface randn - module procedure :: randn1d, randn2d - end interface randn - -contains - - function randn1d(n) result(r) - ! Generates n random numbers with a normal distribution. - integer(ik), intent(in) :: n - real(rk) :: r(n), r2(n) - call random_number(r) - call random_number(r2) - r = sqrt(-2 * log(r)) * cos(2 * pi * r2) - end function randn1d - - function randn2d(m, n) result(r) - ! Generates m x n random numbers with a normal distribution. - integer(ik), intent(in) :: m, n - real(rk) :: r(m, n), r2(m, n) - call random_number(r) - call random_number(r2) - r = sqrt(-2 * log(r)) * cos(2 * pi * r2) - end function randn2d - -end module mod_random diff --git a/src/nf_random_mod.f90 b/src/nf_random_mod.f90 new file mode 100644 index 00000000..66262af0 --- /dev/null +++ b/src/nf_random_mod.f90 @@ -0,0 +1,30 @@ +module nf_random_mod + + ! Provides a random number generator with + ! normal distribution, centered on zero. + + use mod_kinds, only: ik, rk + + implicit none + + private + public :: randn + + interface randn + + module function randn1d(n) result(r) + ! Generates n random numbers with a normal distribution. + implicit none + integer(ik), intent(in) :: n + real(rk) :: r(n) + end function randn1d + + module function randn2d(m, n) result(r) + ! Generates m x n random numbers with a normal distribution. + integer(ik), intent(in) :: m, n + real(rk) :: r(m, n) + end function randn2d + + end interface randn + +end module nf_random_mod diff --git a/src/nf_random_submod.f90 b/src/nf_random_submod.f90 new file mode 100644 index 00000000..16d067b6 --- /dev/null +++ b/src/nf_random_submod.f90 @@ -0,0 +1,26 @@ +submodule(nf_random_mod) nf_random_submod + + ! Provides a random number generator with + ! normal distribution, centered on zero. + + implicit none + + real(rk), parameter :: pi = 4 * atan(1._rk) + +contains + + module procedure randn1d + real(rk) :: r2(n) + call random_number(r) + call random_number(r2) + r = sqrt(-2 * log(r)) * cos(2 * pi * r2) + end procedure randn1d + + module procedure randn2d + real(rk) :: r2(m, n) + call random_number(r) + call random_number(r2) + r = sqrt(-2 * log(r)) * cos(2 * pi * r2) + end procedure randn2d + +end submodule nf_random_submod