CoMD
A Mini-app for Co-Design of Classical Molecular Dynamics.
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
random.c File Reference

Simple random number generators for uniform and Gaussian distributions. More...

#include "random.h"
#include <math.h>
Include dependency graph for random.c:

Go to the source code of this file.

Functions

real_t gasdev (uint64_t *seed)
 Return a random number from a Gaussian distribution. More...
 
double lcg61 (uint64_t *seed)
 Return a random number from a uniform distribution. More...
 
uint64_t mkSeed (uint32_t id, uint32_t callSite)
 Return a seed suitable for calling lcg61 or gasdev. More...
 

Detailed Description

Simple random number generators for uniform and Gaussian distributions.

The generator in lcg61 and the hash in mkSeed aren't really industrial strength, but they're more than good enough for present purposes.

Definition in file random.c.

Function Documentation

real_t gasdev ( uint64_t *  seed)

Return a random number from a Gaussian distribution.

Use the Box-Muller method to sample a Gaussian distribution with zero mean and unit variance. To ensure the same input seed always generates the same returned value we do not use the standard technique of saving one of the two generated randoms for the next call.

Parameters
[in,out]seedSeed for generator.
Returns
A pseudo-random number in the interval (-infinity, infinity).

Definition at line 21 of file random.c.

Here is the call graph for this function:

Here is the caller graph for this function:

double lcg61 ( uint64_t *  seed)

Return a random number from a uniform distribution.

A 61-bit prime modulus linear congruential generator with modulus = 2^61 -1.

Parameters
[in,out]seedSeed for generator.
Returns
A pseudo-random number in the interval [0, 1].

Definition at line 41 of file random.c.

Here is the caller graph for this function:

uint64_t mkSeed ( uint32_t  id,
uint32_t  callSite 
)

Return a seed suitable for calling lcg61 or gasdev.

Forms a 64-bit seed for lcg61 from the combination of 2 32-bit Knuth multiplicative hashes, then runs off 10 values to pass up the worst of the early low-bit correlations.

Parameters
[in]idAn id number such as an atom gid that is unique to each entity that requires random numbers.
[in]callSiteA unique number for each call site in the code that needs to generate random seeds. Using a different value for callSite allows different parts of the code to obtain different random streams for the same id.
Returns
A 64-bit seed that is unique to the id and call site.

Definition at line 65 of file random.c.

Here is the call graph for this function:

Here is the caller graph for this function: