RandomClass Module

It gives Pseudorandom numbers and random operations/functions.



Interfaces

public interface randi

Generate a uniformly distributed random integers

  • public function randi_range_rank2(valrange, size1, size2) result(ret)

    Arguments

    Type IntentOptional Attributes Name
    integer(kind=int32), intent(in) :: valrange(2)
    integer(kind=int32), intent(in) :: size1
    integer(kind=int32), intent(in) :: size2

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

  • public function randi_imax(imax) result(ret)

    Arguments

    Type IntentOptional Attributes Name
    integer(kind=int32), intent(in) :: imax

    Return Value integer(kind=int32)

  • public function randi_imax_n(imax, n) result(ret)

    Arguments

    Type IntentOptional Attributes Name
    integer(kind=int32), intent(in) :: imax
    integer(kind=int32), intent(in) :: n

    Return Value integer(kind=int32), (n)

public interface rand

Generate a uniformly distributed random integers

  • public function rand_n(n) result(ret)

    Arguments

    Type IntentOptional Attributes Name
    integer(kind=int32), intent(in) :: n

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

  • public function rand_sz2(sz1, sz2) result(ret)

    Arguments

    Type IntentOptional Attributes Name
    integer(kind=int32), intent(in) :: sz1
    integer(kind=int32), intent(in) :: sz2

    Return Value real(kind=real64), (sz1,sz2)

  • public function rand_sz3(sz1, sz2, sz3) result(ret)

    Arguments

    Type IntentOptional Attributes Name
    integer(kind=int32), intent(in) :: sz1
    integer(kind=int32), intent(in) :: sz2
    integer(kind=int32), intent(in) :: sz3

    Return Value real(kind=real64), (sz1,sz2,sz3)

public interface EV

Compute expectation value

  • public function ExpectationValue_r64_i32_i32(func, arg1, arg2, arg3) result(ret)

    Arguments

    Type IntentOptional Attributes Name
    public function func(arg1, arg2, arg3) result(ret)
    Arguments
    Type IntentOptional Attributes Name
    real(kind=real64), intent(in) :: arg1
    integer(kind=int32), intent(in) :: arg2
    integer(kind=int32), intent(in) :: arg3
    Return Value real(kind=real64)
    real(kind=real64), intent(in) :: arg1
    integer(kind=int32), intent(in) :: arg2
    integer(kind=int32), intent(in) :: arg3

    Return Value real(kind=real64)


Derived Types

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.

procedure, public :: random => getRandom ../../../

Returns random number in [0,1)

procedure, public :: randint => getRandomInt ../../../

Returns integer random number

procedure, public :: name => nameRandom ../../../

Returns random name

procedure, public :: choiceInt => choiceRandomInt ../../../

Random choice

procedure, public :: choiceReal => choiceRandomReal ../../../

Random choice

procedure, public :: drawOne => drawOneRandomInt ../../../

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

procedure, public :: draw => drawRandomInt ../../../

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

procedure, public :: shuffle => shuffleRandomInt ../../../

Random rearrange of a integer array.

procedure, public :: uniform => uniformRandom ../../../

Generate uniform distribution

procedure, public, pass :: gauss_scalar_Random ../../../

Generate Gaussian distribution

procedure, public, pass :: gauss_vector_Random ../../../

Generate Gaussian distribution

procedure, public, pass :: gauss_tensor_Random ../../../

Generate Gaussian distribution

generic, public :: gauss => gauss_scalar_Random, gauss_vector_Random, gauss_tensor_Random ../../../

Generate Gaussian distribution

procedure, public :: ChiSquared => ChiSquaredRandom ../../../

Generate Chi-Squared distribution

procedure, public :: Cauchy => CauchyRandom ../../../

Generate Cauchy distribution

procedure, public :: Lognormal => LognormalRandom ../../../

Generate Lognormal distribution

procedure, public :: InverseGauss => InverseGaussRandom ../../../

Generate InverseGaussian distribution

procedure, public :: save => saveRandom ../../../

save random number

procedure, public :: white => whiteRandom ../../../

Generate While-Gaussian signal

procedure, public, pass :: randnRandomVector ../../../

Generate a vector of uniform random number.

procedure, public, pass :: randnRandomArray ../../../

Generate a array of uniform random number.

generic, public :: randn => randnRandomArray, randnRandomVector ../../../

Generate a vector/array of uniform random number.

procedure, public :: fill => fillRandom ../../../

Generate a vector of uniform random number.

procedure, public :: histogram => histogramRandom ../../../

Generate a histogram of a vector

procedure, public :: scalar => scalarRandom ../../../

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

procedure, public :: vector => vectorRandom ../../../

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

procedure, public :: matrix => matrixRandom ../../../

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

procedure, public :: cube => cubeRandom ../../../

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


Functions

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)

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)

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)

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)

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)

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, (:)

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, (:,:)

public function nameRandom(obj) result(str)

Arguments

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

Return Value character(len=200)

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)

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)

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)

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)

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)

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, (:,:,:)

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, (:,:)

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, (:)

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

public function randi_range_rank2(valrange, size1, size2) result(ret)

Arguments

Type IntentOptional Attributes Name
integer(kind=int32), intent(in) :: valrange(2)
integer(kind=int32), intent(in) :: size1
integer(kind=int32), intent(in) :: size2

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

public function randi_imax(imax) result(ret)

Arguments

Type IntentOptional Attributes Name
integer(kind=int32), intent(in) :: imax

Return Value integer(kind=int32)

public function randi_imax_n(imax, n) result(ret)

Arguments

Type IntentOptional Attributes Name
integer(kind=int32), intent(in) :: imax
integer(kind=int32), intent(in) :: n

Return Value integer(kind=int32), (n)

public function rand_n(n) result(ret)

Arguments

Type IntentOptional Attributes Name
integer(kind=int32), intent(in) :: n

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

public function rand_sz2(sz1, sz2) result(ret)

Arguments

Type IntentOptional Attributes Name
integer(kind=int32), intent(in) :: sz1
integer(kind=int32), intent(in) :: sz2

Return Value real(kind=real64), (sz1,sz2)

public function rand_sz3(sz1, sz2, sz3) result(ret)

Arguments

Type IntentOptional Attributes Name
integer(kind=int32), intent(in) :: sz1
integer(kind=int32), intent(in) :: sz2
integer(kind=int32), intent(in) :: sz3

Return Value real(kind=real64), (sz1,sz2,sz3)

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, (:)

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)

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, (:)

public function ExpectationValue_r64_i32_i32(func, arg1, arg2, arg3) result(ret)

Arguments

Type IntentOptional Attributes Name
public function func(arg1, arg2, arg3) result(ret)
Arguments
Type IntentOptional Attributes Name
real(kind=real64), intent(in) :: arg1
integer(kind=int32), intent(in) :: arg2
integer(kind=int32), intent(in) :: arg3
Return Value real(kind=real64)
real(kind=real64), intent(in) :: arg1
integer(kind=int32), intent(in) :: arg2
integer(kind=int32), intent(in) :: arg3

Return Value real(kind=real64)


Subroutines

public subroutine initRandom(obj)

Arguments

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

public subroutine saveRandom(obj)

Arguments

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

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(:)

public subroutine shuffleRandomInt(this, intvec)

Arguments

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