31 integer,
intent(in) :: seed
33 integer,
intent(in) :: offset
35 integer :: i, n, clock
36 integer,
allocatable :: seed_vec(:)
40 call system_clock(count = clock)
48 clock = clock + 67 * offset
49 call random_seed(
size = n)
52 seed_vec = clock + 37 * (/ (i - 1, i = 1, n) /)
53 call random_seed(put = seed_vec)
71 call random_number(rnd)
82 integer,
intent(in) :: n
84 call assert(669532625, n >= 1)
99 real(kind=
dp),
intent(in) :: val
137 real(kind=
dp),
intent(in) :: mean
138 real(kind=
dp) :: l, p
141 call assert(368397056, mean >= 0d0)
142 if (mean <= 10d0)
then
176 integer,
intent(in) :: n
178 real(kind=
dp),
intent(in) :: p
179 real(kind=
dp) :: np, nomp, q, g_real
182 call assert(130699849, n >= 0)
183 call assert(754379796, p >= 0d0)
184 call assert(678506029, p <= 1d0)
185 np = real(n, kind=
dp) * p
186 nomp = real(n, kind=
dp) * (1d0 - p)
187 if ((np >= 10d0) .and. (nomp >= 10d0))
then
191 elseif (np < 1d-200)
then
193 elseif (nomp < 1d-200)
then
210 if (g_real > real(n - sum, kind=
dp))
exit
233 real(kind=
dp),
intent(in) :: mean
235 real(kind=
dp),
intent(in) :: stddev
236 real(kind=
dp) :: u1, u2, r, theta, z0, z1
238 call assert(898978929, stddev >= 0d0)
243 r = sqrt(-2d0 * log(u1))
244 theta = 2d0 *
const%pi * u2
262 real(kind=
dp),
intent(in) :: mean(:)
264 real(kind=
dp),
intent(in) :: stddev(
size(mean))
266 real(kind=
dp),
intent(out) :: val(
size(mean))
285 real(kind=
dp),
intent(in) :: pdf(:)
287 real(kind=
dp) :: pdf_max
292 pdf_max = maxval(pdf)
293 if (minval(pdf) < 0d0)
then
294 call die_msg(121838078,
'pdf contains negative values')
296 if (pdf_max <= 0d0)
then
297 call die_msg(119208863,
'pdf is not positive')
300 do while (.not. found)
319 integer,
intent(in) :: pdf(:)
321 integer :: pdf_max, k
325 pdf_max = maxval(pdf)
326 if (minval(pdf) < 0)
then
327 call die_msg(598024763,
'pdf contains negative values')
329 if (pdf_max <= 0)
then
330 call die_msg(109961454,
'pdf is not positive')
333 do while (.not. found)
335 if (
camp_random() < real(pdf(k), kind=
dp) / real(pdf_max, kind=
dp))
then
353 real(kind=
dp),
intent(in) :: vec_cts(:)
355 integer,
intent(in) :: n_samp
357 integer,
intent(out) :: vec_disc(size(vec_cts))
361 call assert(617770167, n_samp >= 0)
365 vec_disc(k) = vec_disc(k) + 1
395 character(len=CAMP_UUID_LEN),
intent(out) :: uuid
423 uuid(20:20) = achar(iachar(
'8') + i - 1)
425 uuid(20:20) = achar(iachar(
'A') + i - 3)
437 integer(kind=i_kind) :: id
440 "Sequential ids can only be generated on the primary "//&
integer, parameter dp
Kind of a double precision real number.
type(const_t), save const
Fixed variable for accessing the constant's values.
Wrapper functions for MPI.
integer function camp_mpi_rank(comm)
Returns the rank of the current process.
subroutine camp_mpi_bcast_integer(val, comm)
Broadcast the given value from process 0 to all other processes.
Random number generators.
character function rand_hex_char()
Generate a random hexadecimal character.
integer function sample_cts_pdf(pdf)
Sample the given continuous 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.
integer function prob_round(val)
Round val to floor(val) or ceiling(val) with probability proportional to the relative distance from v...
integer, parameter camp_uuid_len
Length of a UUID string.
integer function rand_binomial(n, p)
Generate a Binomial-distributed random number with the given parameters.
subroutine camp_rand_finalize()
Cleanup the random number generator.
integer function camp_rand_int(n)
Returns a random integer between 1 and n.
integer function sample_disc_pdf(pdf)
Sample the given discrete probability density function.
subroutine camp_srand(seed, offset)
Initializes the random number generator to the state defined by the given seed plus offset....
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.
integer, private next_id
Next sequential id.
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 deviation...
subroutine uuid4_str(uuid)
Generate a version 4 UUID as a string.
integer function rand_poisson(mean)
Generate a Poisson-distributed random number with the given mean.
real(kind=dp) function camp_random()
Returns a random number between 0 and 1.
Common utility subroutines.
subroutine assert(code, condition_ok)
Errors unless condition_ok is true.
subroutine die_msg(code, error_msg)
Error immediately.
subroutine assert_msg(code, condition_ok, error_msg)
Errors unless condition_ok is true.