Random

class Random

Psuedo random number generator class. Note that all other Random distributions depend upon the uniform distribution, such that reproduction by storage is simplified.

Subclassed by feasst::RandomMT19937, feasst::RandomModulo

Public Functions

void seed_by_time()

Generate seed from time and date.

void seed(const int seed = 1346867550)

Input seed by value for reproducibility.

double uniform()

Return a random real number with a uniform probability distribution between 0 and 1.

int uniform(const int min, const int max)

Return a random integer with a uniform probability distribution betwee min and max.

bool coin_flip()

Randomly return true or false.

double uniform_real(const double min, const double max)

Return random real number with a uniform probability distribution between min and max.

template<class T>
const int index(const std::vector<T> &vector)

Return a random index of a vector.

template<class T>
T *element(std::vector<T> *vector, int *return_index = NULL)

Return a pointer to a random element within a vector.

param return_index:

optionally return the index associated with the element.

template<class T>
const T &const_element(const std::vector<T> &vector, int *return_index = NULL)

Return a constant reference to a random element within a vector.

param return_index:

optionally return the index associated with the element.

std::string alpha_numeric(const int length = 5)

Return a random alpha numeric string of given length.

Position position_in_cube(const int dimension, const double length = 1)

Return a random position within a cube of side length with the origin at the center.

void position_in_cube(const int dimension, const double length, Position *position)

Optimized version of the above, in that an existing position is modified.

Position position_in_cuboid(const Position &side_length)

Return a random position within a cuboid of side lengths with the origin at the center.

void position_in_cuboid(const Position &side_length, Position *position)

Optimized version of the above, in that an existing position is modified.

void unit_sphere_surface(Position *position)

Random point on the surface of a unit sphere.

void position_in_spherical_shell(const double lower, const double upper, Position *position)

Random point in a spherical shell.

int index_from_cumulative_probability(const std::vector<double> &cumulative)

Given a cumulative probability distribution, return a random integer index from a uniform probability distribution. The cumulative distribution must be monotonically nondecreasing. In addition, it must end with the value of unity.

void quaternion(Position *quaternion)

Return a random quaternion using the method of: Franz J. Vesely, J. Comput. Phys., 47, 291-296 (1982).

RotationMatrix rotation(const int dimension, const double tunable = -1)

Return a random rotation matrix.

param dimension:

dimensionality of space

param tunable:

If tunable == -1, generate a completely random rotation (default). Otherwise, In 3D, this is the relative weight of a random quaternion and a unit quaternion corresponding to no rotation. In 2D, this is the maximum rotation angle.

void rotation(const int dimension, Position *quaternion_or_axis, RotationMatrix *rot_mat, const double tunable = -1)

Same as above, but optimized to reuse existing axis and matrix.

param dimension:

dimensionality of space

virtual double standard_normal()

Return the normal distribution with 0 mean and unit sigma (standard). Use Box-Muller transformation. See: https://mathworld.wolfram.com/Box-MullerTransformation.html

double normal(const double mean, const double stdev)

Same as above, but with a given mean and standard deviation.

const Cache &cache() const

Return the cache.

void set_cache_to_load(const bool load)

Set Cache to load.

void set_cache_to_unload(const Random &random)

Set Cache to unload.

std::string class_name() const

Serialize.

Arguments

  • seed: Provide an integer to seed the random number generator. If no seed is provided, but random numbers are requested, then the time will be used to generate a seed.