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
Public Functions
-
Random
(const argtype &args = argtype())¶ args:
seed : Provide an integer to seed the random number generator. If the string “time” is provided, then use the time and date to generate the seed. If no seed is provided, but random numbers are requested, then the time will be used to generate a seed. If the string “default” is provided, then use the default integer included in Random::seed().
-
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
>
T *element
(std::vector<T> *vector, int *return_index = NULL)¶ Return a pointer to a random element within a vector.
- Parameters
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.
- Parameters
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
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.
-
RotationMatrix
rotation
(const int dimension, const double max_angle = 180)¶ Return a random rotation matrix.
- Parameters
dimension
: dimensionality of spacemax_angle
: maximum angle of rotation in degrees.
-
void
rotation
(const int dimension, Position *axis, RotationMatrix *rot_mat, const double max_angle = 180)¶ Same as above, but optimized to reuse existing axis and matrix.
- Parameters
dimension
: dimensionality of spacemax_angle
: maximum angle of rotation in degrees.
-
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.
-
double
harmonic_bond_length
(const double equilibrium_length, const double spring_constant, const int dimension)¶ Return a randomly selected bond length with harmonic potential of the form: betaU ~ spring_constant*(length - equilibrium_length)**2 The typical 1/2 factor is included in spring_constant. prob(length) ~ length**2 exp(-betaU) dlength as described in Frenkel and Smit, Alg 43, page 578 and Allen and Tildesley, Section G.3. The maximal length is 3 sigma beyond the mean. Only currently implemented for 3 dimensions.
-
double
bond_length
(const double equilibrium_length, const double spring_constant, const int exponent, const int dimension)¶ Same as above, but generalized for arbitrary exponential powers. betaU ~ spring_constant*(length - equilibrium_length)**exponent In this implementation, the maximum bond length is twice the equilibrium. If exponent == 2, use harmonic_bond_length.
-
double
bond_angle
(const double equilibrium_angle, const double spring_constant, const int exponent, const int dimension, const double minimum_angle = 0.)¶ - Parameters
minimum_angle
: Optionally, disallow angles < minimum_angle. The max angle is PI.
Return bond angle selected from probability distribution associated with bending energy, \( \beta U=spring_constant*(t-equil_ang)^{exponent} \) from Frenkel and Smit, page 343, below Equation 13.3.6.
-
std::string
class_name
() const¶ Serialize.
-