PartMC 2.1.0
Functions/Subroutines | Variables
pmc_rand Module Reference

Random number generators. More...

Functions/Subroutines

subroutine pmc_srand (seed, offset)
 Initializes the random number generator to the state defined by the given seed plus offset. If the seed is 0 then a seed is auto-generated from the current time plus offset.
subroutine pmc_rand_finalize ()
 Cleanup the random number generator.
real(kind=dp) pmc_random ()
 Returns a random number between 0 and 1.
integer pmc_rand_int (n)
 Returns a random integer between 1 and n.
integer prob_round (val)
 Round val to floor(val) or ceiling(val) with probability proportional to the relative distance from val. That is, Prob(prob_round(val) == floor(val)) = ceil(val) - val.
integer rand_poisson (mean)
 Generate a Poisson-distributed random number with the given mean.
integer rand_binomial (n, p)
 Generate a Binomial-distributed random number with the given parameters.
real(kind=dp) rand_normal (mean, stddev)
 Generates a normally distributed random number with the given mean and standard deviation.
integer sample_cts_pdf (pdf)
 Sample the given continuous probability density function.
integer sample_disc_pdf (pdf)
 Sample the given discrete probability density function.
subroutine sample_vec_cts_to_disc (vec_cts, n_samp, vec_disc)
 Convert a real-valued vector into an integer-valued vector by sampling.
character rand_hex_char ()
 Generate a random hexadecimal character.
subroutine uuid4_str (uuid)
 Generate a version 4 UUID as a string.

Variables

integer, parameter PMC_UUID_LEN = 36
 Length of a UUID string.
integer, parameter PMC_RAND_GSL_SUCCESS = 0
 Result code indicating successful completion.
integer, parameter PMC_RAND_GSL_INIT_FAIL = 1
 Result code indicating initialization failure.
integer, parameter PMC_RAND_GSL_NOT_INIT = 2
 Result code indicating the generator was not initialized when it should have been.
integer, parameter PMC_RAND_GSL_ALREADY_INIT = 3
 Result code indicating the generator was already initialized when an initialization was attempted.

Detailed Description

Random number generators.


Function/Subroutine Documentation

subroutine pmc_rand::pmc_rand_finalize ( )

Cleanup the random number generator.

integer pmc_rand::pmc_rand_int ( integer,intent(in)  n)

Returns a random integer between 1 and n.

Parameters:
nMaximum random number to generate.
real(kind=dp) pmc_rand::pmc_random ( )

Returns a random number between 0 and 1.

subroutine pmc_rand::pmc_srand ( integer,intent(in)  seed,
integer,intent(in)  offset 
)

Initializes the random number generator to the state defined by the given seed plus offset. If the seed is 0 then a seed is auto-generated from the current time plus offset.

Parameters:
seedRandom number generator seed.
offsetRandom number generator offset.
integer pmc_rand::prob_round ( real(kind=dp),intent(in)  val)

Round val to floor(val) or ceiling(val) with probability proportional to the relative distance from val. That is, Prob(prob_round(val) == floor(val)) = ceil(val) - val.

Parameters:
valValue to round.
integer pmc_rand::rand_binomial ( integer,intent(in)  n,
real(kind=dp),intent(in)  p 
)

Generate a Binomial-distributed random number with the given parameters.

See http://en.wikipedia.org/wiki/Binomial_distribution for information on the method. The method used at present is rather inefficient and inaccurate (brute force for $np \le 10$ and $n(1-p) \le 10$, otherwise normal approximation).

For better methods, see L. Devroye, "Non-Uniform Random Variate Generation", Springer-Verlag, 1986.

Parameters:
nSample size.
pSample probability.
character pmc_rand::rand_hex_char ( )

Generate a random hexadecimal character.

real(kind=dp) pmc_rand::rand_normal ( real(kind=dp),intent(in)  mean,
real(kind=dp),intent(in)  stddev 
)

Generates a normally distributed random number with the given mean and standard deviation.

Parameters:
meanMean of distribution.
stddevStandard deviation of distribution.
integer pmc_rand::rand_poisson ( real(kind=dp),intent(in)  mean)

Generate a Poisson-distributed random number with the given mean.

See http://en.wikipedia.org/wiki/Poisson_distribution for information on the method. The method used at present is rather inefficient and inaccurate (brute force for mean below 10 and normal approximation above that point).

The best known method appears to be due to Ahrens and Dieter (ACM Trans. Math. Software, 8(2), 163-179, 1982) and is available (in various forms) from:

Unfortunately the above code is under the non-free license:

For other reasonable methods see L. Devroye, "Non-Uniform Random Variate Generation", Springer-Verlag, 1986.

Parameters:
meanMean of the distribution.
integer pmc_rand::sample_cts_pdf ( real(kind=dp),dimension(:),intent(in)  pdf)

Sample the given continuous probability density function.

That is, return a number k = 1,...,n such that prob(k) = pdf(k) / sum(pdf). Uses accept-reject.

Parameters:
pdfProbability density function (not normalized).
integer pmc_rand::sample_disc_pdf ( integer,dimension(:),intent(in)  pdf)

Sample the given discrete probability density function.

That is, return a number k = 1,...,n such that prob(k) = pdf(k) / sum(pdf). Uses accept-reject.

Parameters:
pdfProbability density function.
subroutine pmc_rand::sample_vec_cts_to_disc ( real(kind=dp),dimension(:),intent(in)  vec_cts,
integer,intent(in)  n_samp,
integer,dimension(size(vec_cts)),intent(out)  vec_disc 
)

Convert a real-valued vector into an integer-valued vector by sampling.

Use n_samp samples. Each discrete entry is sampled with a PDF given by vec_cts. This is very slow for large n_samp or large n.

Parameters:
vec_ctsContinuous vector.
n_sampNumber of discrete samples to use.
vec_discDiscretized vector.
subroutine pmc_rand::uuid4_str ( character(len=PMC_UUID_LEN),intent(out)  uuid)

Generate a version 4 UUID as a string.

See http://en.wikipedia.org/wiki/Universally_Unique_Identifier for format details.

Parameters:
uuidThe newly generated UUID string.

Variable Documentation

integer,parameter pmc_rand::PMC_RAND_GSL_ALREADY_INIT = 3

Result code indicating the generator was already initialized when an initialization was attempted.

integer,parameter pmc_rand::PMC_RAND_GSL_INIT_FAIL = 1

Result code indicating initialization failure.

integer,parameter pmc_rand::PMC_RAND_GSL_NOT_INIT = 2

Result code indicating the generator was not initialized when it should have been.

integer,parameter pmc_rand::PMC_RAND_GSL_SUCCESS = 0

Result code indicating successful completion.

integer,parameter pmc_rand::PMC_UUID_LEN = 36

Length of a UUID string.