Top | ![]() |
![]() |
![]() |
![]() |
NcmRNGNcmRNG — Encapsulated GNU Scientific Library (GSL) random number generator with support for multhreading. |
Functions
NcmRNG * | ncm_rng_new () |
NcmRNG * | ncm_rng_seeded_new () |
NcmRNG * | ncm_rng_ref () |
void | ncm_rng_free () |
void | ncm_rng_clear () |
void | ncm_rng_lock () |
void | ncm_rng_unlock () |
const gchar * | ncm_rng_get_algo () |
gchar * | ncm_rng_get_state () |
void | ncm_rng_set_algo () |
void | ncm_rng_set_state () |
gboolean | ncm_rng_check_seed () |
void | ncm_rng_set_seed () |
gulong | ncm_rng_get_seed () |
void | ncm_rng_set_random_seed () |
NcmRNG * | ncm_rng_pool_get () |
gdouble | ncm_rng_uniform_gen () |
gdouble | ncm_rng_gaussian_gen () |
gdouble | ncm_rng_ugaussian_gen () |
gdouble | ncm_rng_gaussian_tail_gen () |
gdouble | ncm_rng_exponential_gen () |
gdouble | ncm_rng_laplace_gen () |
gdouble | ncm_rng_exppow_gen () |
gdouble | ncm_rng_beta_gen () |
gdouble | ncm_rng_gamma_gen () |
Description
This object encapsulates the GNU Scientific Library (GSL) pseudo random number generator (PRNG). Its main purpose is to add support for saving and loading state and multhreading. For more information about the GSL routines see both links: random number generation and random number distributions.
Functions
ncm_rng_new ()
NcmRNG *
ncm_rng_new (const gchar *algo
);
Creates a new NcmRNG using the algorithm algo
.
See the list of algorithms here.
If algo
is NULL the default algorithm and seed are used.
See this link for more details.
ncm_rng_seeded_new ()
NcmRNG * ncm_rng_seeded_new (const gchar *algo
,gulong seed
);
Creates a new NcmRNG using the algorithm algo
.
See the list of algorithms here.
If algo
is NULL the default algorithm is used.
See this link for more details.
ncm_rng_clear ()
void
ncm_rng_clear (NcmRNG **rng
);
Decreases the reference count of *rng
by one and sets *rng
to NULL.
ncm_rng_get_state ()
gchar *
ncm_rng_get_state (NcmRNG *rng
);
Gets the state of the algorithm in Base64. It can be a very large string depending on the underlining state.
ncm_rng_set_algo ()
void ncm_rng_set_algo (NcmRNG *rng
,const gchar *algo
);
Sets the PRNG algorithm.
ncm_rng_set_state ()
void ncm_rng_set_state (NcmRNG *rng
,const gchar *state
);
Sets the PRNG algorithm state.
ncm_rng_check_seed ()
gboolean ncm_rng_check_seed (NcmRNG *rng
,gulong seed
);
Check if the seed was already used by any NcmRNG.
ncm_rng_get_seed ()
gulong
ncm_rng_get_seed (NcmRNG *rng
);
This functions returns the seed used to initialize the PRNG.
ncm_rng_set_random_seed ()
void ncm_rng_set_random_seed (NcmRNG *rng
,gboolean allow_colisions
);
Sets the algorithm seed using a PRNG seeded by /dev/urandom (Unix/Linux)
or current time, when the first is not available (see
).
If g_rand_new()
allow_colisions
is FALSE this function will set the first unused seed generated.
ncm_rng_pool_get ()
NcmRNG *
ncm_rng_pool_get (const gchar *name
);
Gets the NcmRNG named name
from the pool.
If it doesn't exists, it creates one, add it to the pool and returns it.
ncm_rng_uniform_gen ()
gdouble ncm_rng_uniform_gen (NcmRNG *rng
,const gdouble xl
,const gdouble xu
);
This functions returns a random number drawn from the
uniform distribution between the values xl
and xu
.
ncm_rng_gaussian_gen ()
gdouble ncm_rng_gaussian_gen (NcmRNG *rng
,const gdouble mu
,const gdouble sigma
);
This function returns a random number drawn from the
Gaussian distribution,
with mean mu
and standard deviation sigma
.
ncm_rng_ugaussian_gen ()
gdouble
ncm_rng_ugaussian_gen (NcmRNG *rng
);
This function returns a random number drwan from the
Gaussian distribution,
with mean zero and standard deviation one.
Equivalent as above but with mean
= 0 and sigma
= 1.
ncm_rng_gaussian_tail_gen ()
gdouble ncm_rng_gaussian_tail_gen (NcmRNG *rng
,const gdouble a
,const gdouble sigma
);
This function returns a random number drawn from the upper tail of the
Gaussian distribution with standard deviation sigma
.
The value returned is larger than the lower limit a
, which must be positive.
ncm_rng_exponential_gen ()
gdouble ncm_rng_exponential_gen (NcmRNG *rng
,const gdouble mu
);
This function returns a random number drawn from the
exponential distribution
with scale parameter (mean) mu
.
ncm_rng_laplace_gen ()
gdouble ncm_rng_laplace_gen (NcmRNG *rng
,const gdouble a
);
This function returns a random number drawn from the
Laplace distribution
with width a
.
ncm_rng_exppow_gen ()
gdouble ncm_rng_exppow_gen (NcmRNG *rng
,const gdouble a
,const gdouble b
);
This function returns a random number drawn from the
exponential power distribution
with scale parameter a
and exponent b
.
ncm_rng_beta_gen ()
gdouble ncm_rng_beta_gen (NcmRNG *rng
,const gdouble a
,const gdouble b
);
This function returns a random number drawn from the
beta distribution
with shape parameters a
and b
. The shape parameters must be positive.
ncm_rng_gamma_gen ()
gdouble ncm_rng_gamma_gen (NcmRNG *rng
,const gdouble a
,const gdouble b
);
This function returns a random number drawn from the
gamma distribution
with shape parameter a
and scale parameter b
.
Property Details
The “algorithm”
property
“algorithm” char *
The name of the pseudo random number algorithm to be used from GNU Scientific Library (GSL). A list of the available algorithms can be find here.
Owner: NcmRNG
Flags: Read / Write / Construct
Default value: "mt19937"
The “seed”
property
“seed” gulong
Pseudo random number algorithm seed.
Owner: NcmRNG
Flags: Read / Write