NuMFor 9f2ab49 (2024-04-08)
Numerical (Modern) Fortran. Library for Simple Numerical computing
Random distributions

Modules

module  exponential
 Exponential random distribution The exponential probability distribution located at $x_{0}$ and mean $\mu$, is given by.
 
module  gauss
 Normal random distribution The normal probability distribution located at $x_{0}$ and standard deviation $\sigma$, is given by.
 
module  uniform
 Uniform Random distribution Description: randist.
 

Data Types

interface  random_normal
 Fills a scalar or array with random numbers following a normal (gaussian) distribution. More...
 

Detailed Description


Data Type Documentation

◆ gauss::random_normal

interface gauss::random_normal

Fills a scalar or array with random numbers following a normal (gaussian) distribution.

The general signature is call random_normal([[loc,] scale,] x) where the center loc= $x_{0}$ and the scale= $\sigma$ are optional, and x may be a scalar, vector (1D array), matrix (2D array), 3D-array, 4D-array, or 5D-array.

The following uses are all valid, except the last one

USE numfor, only: random_normal
call random_normal(x) ! Valid. Standard normal (loc=0, scale=1)
call random_normal(scale, x) ! Valid. loc=0
call random_normal(loc, scale, x) ! Valid
call random_normal(loc, x) ! INVALID
!

Example:

program test_rand_gauss
use numfor, only: dp, zero, str, random_seed, random_normal
implicit none
real(dp), dimension(2, 3) :: samples
call random_seed(0) ! Uses default seed
call random_normal(loc=1._dp, scale=2._dp, x=samples)
print "(A)", str(samples)
! Outputs:
! [[ 2.579691898234, -0.3742516980564]
! [ 1.1897226266753, 1.4022523097265]
! [ 0.4435270050626, 0.8899184474152]]
end program test_rand_gauss