Random_ Derived Type

type, public :: Random_

A class for random number


Components

Type Visibility Attributes Name Initial
integer(kind=int32), public :: random_int

it will be deplicated.

integer(kind=int32), public, allocatable :: random_int_seed(:)

It is a seed number

integer(kind=int32), public, allocatable :: random_int_vec(:)

it will be deplicated.

real(kind=real64), public :: random_real

it will be deplicated.

real(kind=real64), public, allocatable :: random_real_vec(:)

it will be deplicated.


Type-Bound Procedures

procedure, public :: init => initRandom

It initializes the random number by a seed.

  • public subroutine initRandom(obj)

    Arguments

    Type IntentOptional Attributes Name
    class(Random_), intent(inout) :: obj

procedure, public :: random => getRandom

Returns random number in [0,1)

  • public function getRandom(obj, distribution) result(x)

    Arguments

    Type IntentOptional Attributes Name
    class(Random_) :: obj
    character(len=*), intent(in), optional :: distribution

    Return Value real(kind=real64)

procedure, public :: randint => getRandomInt

Returns integer random number

  • public function getRandomInt(obj, From, To) result(x)

    Arguments

    Type IntentOptional Attributes Name
    class(Random_), intent(in) :: obj
    integer(kind=int32), intent(in) :: From
    integer(kind=int32), intent(in) :: To

    Return Value integer(kind=int32)

procedure, public :: name => nameRandom

Returns random name

  • public function nameRandom(obj) result(str)

    Arguments

    Type IntentOptional Attributes Name
    class(Random_), intent(inout) :: obj

    Return Value character(len=200)

procedure, public :: choiceInt => choiceRandomInt

Random choice

  • public function choiceRandomInt(obj, Vector, Array) result(val)

    Arguments

    Type IntentOptional Attributes Name
    class(Random_), intent(in) :: obj
    integer(kind=int32), intent(in), optional :: Vector(:)
    integer(kind=int32), intent(in), optional :: Array(:,:)

    Return Value integer(kind=int32)

procedure, public :: choiceReal => choiceRandomReal

Random choice

  • public function choiceRandomReal(obj, Vector, Array) result(val)

    Arguments

    Type IntentOptional Attributes Name
    class(Random_), intent(in) :: obj
    real(kind=real64), intent(in), optional :: Vector(:)
    real(kind=real64), intent(in), optional :: Array(:,:)

    Return Value real(kind=real64)

procedure, public :: drawOne => drawOneRandomInt

Random choice, and the number of the set will be (-1)

  • public function drawOneRandomInt(this, vec) result(ret)

    Arguments

    Type IntentOptional Attributes Name
    class(Random_), intent(in) :: this
    integer(kind=int32), intent(inout), allocatable :: vec(:)

    Return Value integer(kind=int32)

procedure, public :: draw => drawRandomInt

Random choice, and the number of the set will be (-n)

  • public recursive function drawRandomInt(this, vec, num) result(ret)

    Arguments

    Type IntentOptional Attributes Name
    class(Random_), intent(in) :: this
    integer(kind=int32), intent(inout), allocatable :: vec(:)
    integer(kind=int32), intent(in) :: num

    Return Value integer(kind=int32), allocatable, (:)

procedure, public :: shuffle => shuffleRandomInt

Random rearrange of a integer array.

  • public subroutine shuffleRandomInt(this, intvec)

    Arguments

    Type IntentOptional Attributes Name
    class(Random_), intent(in) :: this
    integer(kind=int32), intent(inout) :: intvec(:)

procedure, public :: uniform => uniformRandom

Generate uniform distribution

  • public function uniformRandom(obj, From, To) result(x)

    Arguments

    Type IntentOptional Attributes Name
    class(Random_), intent(in) :: obj
    real(kind=real64), intent(in) :: From
    real(kind=real64), intent(in) :: To

    Return Value real(kind=real64)

procedure, public, pass :: gauss_scalar_Random

Generate Gaussian distribution

  • public function gauss_scalar_Random(obj, mu, sigma) result(ret)

    Arguments

    Type IntentOptional Attributes Name
    class(Random_), intent(inout) :: obj
    real(kind=real64), intent(in) :: mu
    real(kind=real64), intent(in) :: sigma

    Return Value real(kind=real64)

procedure, public, pass :: gauss_vector_Random

Generate Gaussian distribution

  • public function gauss_vector_Random(obj, mu, sigma, n) result(ret)

    Arguments

    Type IntentOptional Attributes Name
    class(Random_), intent(inout) :: obj
    real(kind=real64), intent(in) :: mu
    real(kind=real64), intent(in) :: sigma
    integer(kind=int32), intent(in) :: n

    Return Value real(kind=real64), (n)

procedure, public, pass :: gauss_tensor_Random

Generate Gaussian distribution

  • public function gauss_tensor_Random(obj, mu, sigma, n, m) result(ret)

    Arguments

    Type IntentOptional Attributes Name
    class(Random_), intent(inout) :: obj
    real(kind=real64), intent(in) :: mu
    real(kind=real64), intent(in) :: sigma
    integer(kind=int32), intent(in) :: n
    integer(kind=int32), intent(in) :: m

    Return Value real(kind=real64), (n,m)

Generate Gaussian distribution

  • public function gauss_scalar_Random(obj, mu, sigma) result(ret)

    Arguments

    Type IntentOptional Attributes Name
    class(Random_), intent(inout) :: obj
    real(kind=real64), intent(in) :: mu
    real(kind=real64), intent(in) :: sigma

    Return Value real(kind=real64)

  • public function gauss_vector_Random(obj, mu, sigma, n) result(ret)

    Arguments

    Type IntentOptional Attributes Name
    class(Random_), intent(inout) :: obj
    real(kind=real64), intent(in) :: mu
    real(kind=real64), intent(in) :: sigma
    integer(kind=int32), intent(in) :: n

    Return Value real(kind=real64), (n)

  • public function gauss_tensor_Random(obj, mu, sigma, n, m) result(ret)

    Arguments

    Type IntentOptional Attributes Name
    class(Random_), intent(inout) :: obj
    real(kind=real64), intent(in) :: mu
    real(kind=real64), intent(in) :: sigma
    integer(kind=int32), intent(in) :: n
    integer(kind=int32), intent(in) :: m

    Return Value real(kind=real64), (n,m)

procedure, public :: ChiSquared => ChiSquaredRandom

Generate Chi-Squared distribution

  • public function ChiSquaredRandom(obj, k) result(ret)

    Arguments

    Type IntentOptional Attributes Name
    class(Random_), intent(inout) :: obj
    real(kind=real64), intent(in) :: k

    Return Value real(kind=real64)

procedure, public :: Cauchy => CauchyRandom

Generate Cauchy distribution

  • public function CauchyRandom(obj, mu, gamma) result(ret)

    Arguments

    Type IntentOptional Attributes Name
    class(Random_), intent(inout) :: obj
    real(kind=real64), intent(in) :: mu
    real(kind=real64), intent(in) :: gamma

    Return Value real(kind=real64)

procedure, public :: Lognormal => LognormalRandom

Generate Lognormal distribution

  • public function LognormalRandom(obj, mu, sigma) result(ret)

    Arguments

    Type IntentOptional Attributes Name
    class(Random_), intent(inout) :: obj
    real(kind=real64), intent(in) :: mu
    real(kind=real64), intent(in) :: sigma

    Return Value real(kind=real64)

procedure, public :: InverseGauss => InverseGaussRandom

Generate InverseGaussian distribution

  • public function InverseGaussRandom(obj, mu, lambda) result(ret)

    Arguments

    Type IntentOptional Attributes Name
    class(Random_), intent(inout) :: obj
    real(kind=real64), intent(in) :: mu
    real(kind=real64), intent(in) :: lambda

    Return Value real(kind=real64)

procedure, public :: save => saveRandom

save random number

  • public subroutine saveRandom(obj)

    Arguments

    Type IntentOptional Attributes Name
    class(Random_), intent(inout) :: obj

procedure, public :: white => whiteRandom

Generate While-Gaussian signal

  • public function whiteRandom(this, num_sample, mu, sigma) result(ret)

    Arguments

    Type IntentOptional Attributes Name
    class(Random_), intent(inout) :: this
    integer(kind=int32), intent(in) :: num_sample
    real(kind=real64), intent(in), optional :: mu
    real(kind=real64), intent(in), optional :: sigma

    Return Value real(kind=real64), allocatable, (:)

procedure, public, pass :: randnRandomVector

Generate a vector of uniform random number.

  • public function randnRandomVector(obj, d0) result(array)

    Arguments

    Type IntentOptional Attributes Name
    class(Random_), intent(inout) :: obj
    integer(kind=int32), intent(in) :: d0

    Return Value real(kind=real64), allocatable, (:)

procedure, public, pass :: randnRandomArray

Generate a array of uniform random number.

  • public function randnRandomArray(obj, d0, d1) result(array)

    Arguments

    Type IntentOptional Attributes Name
    class(Random_), intent(inout) :: obj
    integer(kind=int32), intent(in) :: d0
    integer(kind=int32), intent(in) :: d1

    Return Value real(kind=real64), allocatable, (:,:)

generic, public :: randn => randnRandomArray, randnRandomVector

Generate a vector/array of uniform random number.

  • public function randnRandomArray(obj, d0, d1) result(array)

    Arguments

    Type IntentOptional Attributes Name
    class(Random_), intent(inout) :: obj
    integer(kind=int32), intent(in) :: d0
    integer(kind=int32), intent(in) :: d1

    Return Value real(kind=real64), allocatable, (:,:)

  • public function randnRandomVector(obj, d0) result(array)

    Arguments

    Type IntentOptional Attributes Name
    class(Random_), intent(inout) :: obj
    integer(kind=int32), intent(in) :: d0

    Return Value real(kind=real64), allocatable, (:)

procedure, public :: fill => fillRandom

Generate a vector of uniform random number.

  • public subroutine fillRandom(obj, array, vector)

    Arguments

    Type IntentOptional Attributes Name
    class(Random_), intent(inout) :: obj
    real(kind=real64), intent(inout), optional :: array(:,:)
    real(kind=real64), intent(inout), optional :: vector(:)

procedure, public :: histogram => histogramRandom

Generate a histogram of a vector

  • public function histogramRandom(obj, list, division) result(histogram)

    Arguments

    Type IntentOptional Attributes Name
    class(Random_), intent(inout) :: obj
    real(kind=real64), intent(in) :: list(:)
    integer(kind=int32), intent(in), optional :: division

    Return Value real(kind=real64), allocatable, (:,:)

procedure, public :: scalar => scalarRandom

Generate a random scalar of uniform distribution [0,1)

  • public function scalarRandom(obj, size1) result(ret)

    Arguments

    Type IntentOptional Attributes Name
    class(Random_), intent(inout) :: obj
    integer(kind=int32), intent(in) :: size1

    Return Value real(kind=real64), allocatable

procedure, public :: vector => vectorRandom

Generate a random vector of uniform distribution [0,1)

  • public function vectorRandom(obj, size1) result(ret)

    Arguments

    Type IntentOptional Attributes Name
    class(Random_), intent(inout) :: obj
    integer(kind=int32), intent(in) :: size1

    Return Value real(kind=real64), allocatable, (:)

procedure, public :: matrix => matrixRandom

Generate a random matrix of uniform distribution [0,1)

  • public function matrixRandom(obj, size1, size2) result(ret)

    Arguments

    Type IntentOptional Attributes Name
    class(Random_), intent(inout) :: obj
    integer(kind=int32), intent(in) :: size1
    integer(kind=int32), intent(in) :: size2

    Return Value real(kind=real64), allocatable, (:,:)

procedure, public :: cube => cubeRandom

Generate a random cube (3rd order tensor) of uniform distribution [0,1)

  • public function cubeRandom(obj, size1, size2, size3) result(ret)

    Arguments

    Type IntentOptional Attributes Name
    class(Random_), intent(inout) :: obj
    integer(kind=int32), intent(in) :: size1
    integer(kind=int32), intent(in) :: size2
    integer(kind=int32), intent(in) :: size3

    Return Value real(kind=real64), allocatable, (:,:,:)