CAMP 1.0.0
Chemistry Across Multiple Phases
|
Random number generators. More...
Functions/Subroutines | |
subroutine | camp_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 | camp_rand_finalize () |
Cleanup the random number generator. | |
real(kind=dp) function | camp_random () |
Returns a random number between 0 and 1. | |
integer function | camp_rand_int (n) |
Returns a random integer between 1 and n. | |
integer function | 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 function | rand_poisson (mean) |
Generate a Poisson-distributed random number with the given mean. | |
integer function | rand_binomial (n, p) |
Generate a Binomial-distributed random number with the given parameters. | |
real(kind=dp) function | rand_normal (mean, stddev) |
Generates a normally distributed random number with the given mean and standard deviation. | |
subroutine | rand_normal_array_1d (mean, stddev, val) |
Generates a vector of normally distributed random numbers with the given means and standard deviations. This is a set of normally distributed scalars, not a normally distributed vector. | |
integer function | sample_cts_pdf (pdf) |
Sample the given continuous probability density function. | |
integer function | 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 function | rand_hex_char () |
Generate a random hexadecimal character. | |
subroutine | uuid4_str (uuid) |
Generate a version 4 UUID as a string. | |
integer(kind=i_kind) function | generate_int_id () |
Generate an integer id Ids will be sequential, and can only be generated by the primary process. | |
Variables | |
integer, parameter | camp_uuid_len = 36 |
Length of a UUID string. | |
integer, private | next_id = 100 |
Next sequential id. | |
Random number generators.
subroutine camp_rand::camp_rand_finalize |
integer function camp_rand::camp_rand_int | ( | integer, intent(in) | n | ) |
real(kind=dp) function camp_rand::camp_random |
subroutine camp_rand::camp_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.
[in] | seed | Random number generator seed. |
[in] | offset | Random number generator offset. |
Definition at line 28 of file rand.F90.
integer(kind=i_kind) function camp_rand::generate_int_id |
integer function camp_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.
[in] | val | Value to round. |
Definition at line 96 of file rand.F90.
integer function camp_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.
[in] | n | Sample size. |
[in] | p | Sample probability. |
Definition at line 173 of file rand.F90.
character function camp_rand::rand_hex_char |
real(kind=dp) function camp_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.
[in] | mean | Mean of distribution. |
[in] | stddev | Standard deviation of distribution. |
Definition at line 230 of file rand.F90.
subroutine camp_rand::rand_normal_array_1d | ( | real(kind=dp), dimension(:), intent(in) | mean, |
real(kind=dp), dimension(size(mean)), intent(in) | stddev, | ||
real(kind=dp), dimension(size(mean)), intent(out) | val | ||
) |
Generates a vector of normally distributed random numbers with the given means and standard deviations. This is a set of normally distributed scalars, not a normally distributed vector.
[in] | mean | Array of means. |
[in] | stddev | Array of standard deviations. |
[out] | val | Array of sampled normal random variables. |
Definition at line 259 of file rand.F90.
integer function camp_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.
[in] | mean | Mean of the distribution. |
Definition at line 134 of file rand.F90.
integer function camp_rand::sample_cts_pdf | ( | real(kind=dp), dimension(:), intent(in) | ) |
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.
[in] | Probability density function (not normalized). |
Definition at line 282 of file rand.F90.
integer function camp_rand::sample_disc_pdf | ( | integer, dimension(:), intent(in) | ) |
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.
[in] | Probability density function. |
Definition at line 316 of file rand.F90.
subroutine camp_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.
[in] | vec_cts | Continuous vector. |
[in] | n_samp | Number of discrete samples to use. |
[out] | vec_disc | Discretized vector. |
Definition at line 350 of file rand.F90.
subroutine camp_rand::uuid4_str | ( | character(len=camp_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.
[out] | uuid | The newly generated UUID string. |
Definition at line 392 of file rand.F90.
integer, parameter camp_rand::camp_uuid_len = 36 |