Class Random¶
- Defined in File rand_distributions.h
Class Documentation¶
-
class
Random¶ rand_distributions.h
Purpose: Static class for getting randomly created objects from different distributions and of different types.
Copyright (C) 2018 Zayd Hammoudeh. All rights reserved.
- Author
- Zayd Hammoudeh zayd@ucsc.edu
- Version
- 0.00.00
This software may be modified and distributed under the terms of the MIT license. See the LICENSE file for details.
Unnamed Group
-
template <typename T>
static Tuniform(T min, T max)¶ Generates a uniform random integer in the range [min, max].
- Return
- Uniform random integer across the full range of possible values.
- Parameters
min: Minimum value that can be generated inclusive.max: Maximum value that can be generated inclusively.
-
static int
uniform(int min = INT_MIN, int max = INT_MAX)¶ Special int uniform random generator that can optionally avoid reinitialize the uniform int distribution generator.
Public Static Functions
-
static void
init(SolverConfiguration *config)¶ Random State Initializer
Creates the random state of the program. It also seeds the random number generator.
- Parameters
config: Solver configuration
-
static SampleSize
binom(SampleSize n, double p)¶ Creates a random variable sampled from the distribution Binom(n,p)
- Return
- Integer random variable generated according to the binomial distribution.
- Parameters
n: Number of Bernoulli trials in the binomial distributionp: Probability of success.
-
template <typename ListType, typename CountType>
static voidDownsampleList(CountType target_size, std::vector<ListType> &oversampled_vec, bool resize = true)¶ Using a modified version of the Fisher-Yates shuffle, the first
target_sizeelements of the vectoroversampled_vecwill be selected uniformly at random. All modifications are done inplace. The running time is O(target_size).- Template Parameters
ListType: Type of the object in the oversampled vector.CountType: Type of object used to store the counts.
- Parameters
oversampled_vec: Vector with more elements than desired.target_sizeelements will be selected in the first [0,target_size) elements.target_size: Number of objects to select inoversampled_vecresize: True to resizeoversampled_vecto the sizetarget_count.
-
template <typename T>
static voidshuffle(std::vector<T> &vec)¶ Shuffles the specified vector in place uniformly at random.
- Template Parameters
T: Vector element type
- Parameters
vec: Vector to be shuffled.
-
static void
SelectRangeInts(SampleSize max_id, SampleSize num_elements, std::vector<SampleSize> &samples_to_replace)¶ Builds a randomly selected list of integers in the range [0,
max_id).This is performed WITHOUT replacement. Its running time is Theta(
max_id)- Parameters
max_id: Maximum value (exclusive) that any integer in the range can be.num_elements: Number of elements to be selectedsamples_to_replace: List of p num_elements randomly selected integers in the range [0,max_id).
-
template <typename T>
static voidshuffle(typename std::vector<T>::iterator begin, typename std::vector<T>::iterator end)¶ Shuffles a vector using the standad random device.
- Template Parameters
T: Type contained in the vector
- Parameters
begin: Beginning of the vector to shuffle (inclusive)end: End of the vector to shuffle (exclusive)
-
class
Mpz¶ Public Static Functions
-
static void
uniform(mpz_class max_z, mpz_class &rand_val)¶ Generates and returns a random multiprecision integer. This may be used by other classes to consolidate the random MP generation.
- Parameters
max_z: Maximum integer value. All generated random values will be in the range [0, max_z).rand_val: Output value where the generated random number will be stored.
-
static SampleSize
binom(SampleSize n, const mpz_class &t, const mpz_class &a)¶ Selects a binomially distributed random variable from Binom(n, a/t).
It may an approximate or exact version of the distribution depending on the state of the variable Random::Mpz::use_approx_binom_.
- Return
- Integer random variable generated according to the binomial distribution.
- Parameters
n: Number of Bernoulli trials in the binomial distributiont: Total weight of all samplesa: Weight of success.
-
static void