libsc  2.8.7
The SC library provides support for parallel scientific applications.
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
Typedefs | Functions
sc_random.h File Reference

Provide pseudo-random generator and Poisson sampling. More...

#include <sc.h>
Include dependency graph for sc_random.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Typedefs

typedef uint64_t sc_rand_state_t
 The internal state of sc_rand and derived functions. More...
 

Functions

double sc_rand (sc_rand_state_t *state)
 Draw a (pseudo-)random variable uniformly distributed in [0, 1). More...
 
double sc_rand_normal (sc_rand_state_t *state, double *second_result)
 Sample the Gauss standard normal distribution. More...
 
int sc_rand_small (sc_rand_state_t *state, double d)
 Randomly draw either 0 or 1 where the probability for 1 is small. More...
 
int sc_rand_poisson (sc_rand_state_t *state, double mean)
 Draw from a random variable following the Poisson distribution. More...
 

Detailed Description

Provide pseudo-random generator and Poisson sampling.

Typedef Documentation

◆ sc_rand_state_t

typedef uint64_t sc_rand_state_t

The internal state of sc_rand and derived functions.

Can be set arbitrarily to obtain reproducible pseudo random numbers.

Function Documentation

◆ sc_rand()

double sc_rand ( sc_rand_state_t state)

Draw a (pseudo-)random variable uniformly distributed in [0, 1).

Parameters
[in,out]stateInternal state of random number generator.
Returns
Number in [0, 1).

◆ sc_rand_normal()

double sc_rand_normal ( sc_rand_state_t state,
double *  second_result 
)

Sample the Gauss standard normal distribution.

Implements polar form of the Box Muller transform based on sc_rand.

Parameters
[in,out]stateInternal state of random number generator.
[in,out]second_resultWe compute two independent samples. The first is the return value. The second is placed in *second_result unless second_result == NULL.
Returns
Random sample from the standard normal distribution.

◆ sc_rand_poisson()

int sc_rand_poisson ( sc_rand_state_t state,
double  mean 
)

Draw from a random variable following the Poisson distribution.

Parameters
[in,out]stateInternal state of random number generator.
[in]meanMean value of Poisson distribution.
Returns
Non-negative integer.

◆ sc_rand_small()

int sc_rand_small ( sc_rand_state_t state,
double  d 
)

Randomly draw either 0 or 1 where the probability for 1 is small.

Parameters
[in,out]stateInternal state of random number generator.
[in]dProbability of drawing ones.
Returns
0 or 1.