Total Variation Deconvolution using Split Bregman
Macros | Functions
randmt: Samplers using a specified generator

Macros

#define rand_unif_r(generator)
 Generate a uniform random number on (0,1) (reentrant) More...
 
#define rand_normal_r(generator)
 Generate a standard normal distributed random number (reentrant) More...
 
#define rand_exp_r(generator, mu)
 Generate an exponentially-distributed number (reentrant) More...
 
#define rand_geometric_r(generator, p)
 Generate a geometrically-distributed number (reentrant) More...
 

Functions

randmt_tnew_randmt ()
 Create a new randmt_t. More...
 
void free_randmt (randmt_t *generator)
 Free a randmt_t. More...
 
void init_randmt_r (randmt_t *generator, unsigned long seed)
 Initialize randmt_t with a seed. More...
 
void init_randmt_auto_r (randmt_t *generator)
 Initialize generator with the current time and memory address. More...
 
unsigned long rand_uint32_r (randmt_t *generator)
 Generate a random 32-bit unsigned integer (reentrant) More...
 
double rand_gamma_r (randmt_t *generator, double a, double b)
 Generate a Gamma-distributed number (reentrant) More...
 
double rand_poisson_r (randmt_t *generator, double mu)
 Generate a Poisson-distributed number (reentrant) More...
 

Detailed Description

These functions use a specified randmt_t to generate pseudorandom numbers.

Macro Definition Documentation

#define rand_exp_r (   generator,
  mu 
)
Value:
( \
-(mu)*log(rand_unif_r(generator)))

Generate an exponentially-distributed number (reentrant)

Parameters
generatorthe randmt_t
mumean parameter of the distribution (positive value)
Returns
Pseudo-random exponentially-distibuted value with mean mu
See Also
rand_exp()

Generates a pseudo-random exponentially distributed value using the specified generator.

Definition at line 263 of file randmt.h.

#define rand_geometric_r (   generator,
 
)
Value:
( \
floor(log(rand_unif_r(generator))/log(1 - p)) + 1)

Generate a geometrically-distributed number (reentrant)

Parameters
generatorthe randmt_t
pprobability of success
Returns
Pseudo-random geometrically-distibuted value
See Also
rand_geometric()

Generates a pseudo-random geometrically-distributed value using the specified generator.

Definition at line 276 of file randmt.h.

#define rand_normal_r (   generator)
Value:
( \
sqrt(-2.0*log(rand_unif_r(generator))) \
* cos(2.0*M_PI*rand_unif_r(generator)))

Generate a standard normal distributed random number (reentrant)

Parameters
generatorthe randmt_t
Returns
Pseudo-random double value with standard normal distribution
See Also
rand_normal()

A pseudo-random normally distributed number using the specified generator.

Definition at line 249 of file randmt.h.

#define rand_unif_r (   generator)
Value:
( \
(((rand_uint32_r(generator) >> 5)*67108864.0 \
+ (rand_uint32_r(generator) >> 6)) \
+ 0.4999999999999998) / 9007199254740992.0)

Generate a uniform random number on (0,1) (reentrant)

Parameters
generatorthe randmt_t
Returns
Pseudo-random double value in the open interval (0,1)
See Also
rand_unif()

This routine generates a random number uniformly on the open interval (0,1) with 53-bit resolution using the specified generator. The formula used to generate the number is

\[ \mathtt{rand\_unif} = (a 2^{26} + b + 0.5 - \epsilon) / 2^{53}, \]

where a = integer of 27 random bits, b = integer of 26 random bits.

Definition at line 236 of file randmt.h.

Function Documentation

void free_randmt ( randmt_t generator)

Free a randmt_t.

Parameters
generatorthe randmt_t to free
See Also
new_randmt()

Free memory associated to a randmt_t that was created using new_randmt().

Definition at line 121 of file randmt.c.

void init_randmt_auto_r ( randmt_t generator)

Initialize generator with the current time and memory address.

Parameters
generatorthe randmt_t
See Also
init_randmt_auto()
init_randmt_r()

The generator is seeded using the current time added to the memory address of the generator. The memory address is included so that different generators are initialized with different seeds. An array of generators can be initialized as

randmt_t *generators[16];
int i;
for(i = 0; i < 16; i++)
init_randmt_auto_r(generators[i]);

Definition at line 162 of file randmt.c.

void init_randmt_r ( randmt_t generator,
unsigned long  seed 
)

Initialize randmt_t with a seed.

Parameters
generatorthe randmt_t
seedthe seed value
See Also
init_randmt()
init_randmt_auto_r()

Definition at line 130 of file randmt.c.

randmt_t* new_randmt ( )

Create a new randmt_t.

Returns
a randmt_t pointer, or NULL on failure
See Also
init_randmt_auto_r()
init_randmt_r()
free_randmt()

A newly-created randmt_t should be seeded with init_randmt_auto_r() or init_randmt_r(). After use, call free_randmt() to free memory associated with the randmt_t.

randmt_t *generator = NULL;
int i;
if(!(generator = new_randmt()))
exit(1);
init_randmt_auto_r(generator);
for(i = 0; i < 10; i++)
printf("%f\n", rand_unif_r(generator));
free_randmt(generator);

Definition at line 106 of file randmt.c.

double rand_gamma_r ( randmt_t generator,
double  a,
double  b 
)

Generate a Gamma-distributed number (reentrant)

Parameters
generatorthe randmt_t
ashape parameter (positive value)
bscale parameter (positive value)
Returns
Pseudo-random Gamma-distibuted value
See Also
rand_gamma()

Generates a Gamma-distributed random value using the specified generator.

Definition at line 241 of file randmt.c.

double rand_poisson_r ( randmt_t generator,
double  mu 
)

Generate a Poisson-distributed number (reentrant)

Parameters
generatorthe randmt_t
muthe mean parameter of the distribution (positive value)
Returns
Pseudo-random Poisson-distibuted value
See Also
rand_poisson()

A pseudo-random normally distributed number using the specified generator.

Definition at line 318 of file randmt.c.

unsigned long rand_uint32_r ( randmt_t generator)

Generate a random 32-bit unsigned integer (reentrant)

Parameters
generatorthe randmt_t
Returns
Pseudo-random integer value uniformly between 0 and 0xFFFFFFFF
See Also
rand_uint32()

Generates a pseudorandom 32-bit integer value uniformly between 0 and 0xFFFFFFFF using the specified generator.

Definition at line 189 of file randmt.c.