NuMFor 9f2ab49 (2024-04-08)
Numerical (Modern) Fortran. Library for Simple Numerical computing
random_sample Interface Reference

Uniform Random distributions Fills a scalar or array with random numbers in the half-open interval [0, 1). More...

Detailed Description

Uniform Random distributions Fills a scalar or array with random numbers in the half-open interval [0, 1).

The signature is call random_sample(x) where x may be a scalar, vector (1D array), matrix (2D array), 3D-array, 4D-array, or 5D-array.

To sample uniformly over $[a, b)$ with $b > a$, multiply the output of random_sample by $(b-a)$ and add $a$:

call random_sample(x)
y =(b - a) * x + a
Note
The subroutine is implemented to work with arrays of up to five dimensions. Versions for arrays of larger dimensionality may be implemented straightforwardly.

Example:

real(dp), dimension(2, 3) :: r1
call random_seed(0) ! Uses the default seed
! 2d-array of random numbers
call random_sample(r1)
print "(A)", str(r1)
! Outputs:
! [[ 0.7868209548678, 0.250480340688]
! [ 0.7106712289787, 0.946667800961]
! [ 0.0192710581958, 0.4049021448162]]

The documentation for this interface was generated from the following file: