A small pseudo-random number generation library for reproducible execution paths in C/C++.
src: contains all the source files, Makefile, and bash script required to build thelibRandomizer.sofile.testing: contains usage examples of the Randomizer library.
- C++17
- Make
- Navigate into
src. - Issue the command
sh Initialize.shto prepare the environment before creating the library file. - Issue the command
make. This will generate and place the library file inres/libRandomizer.so. - You can now copy the shared object file
res/libRandomizer.soto a desired location for your project. - If you intend to integrate
Randomizerto a C++ project, you should copy the header filesrc/Randomizer.hppto a desired location for your project. - If you intend to integrate
Randomizerto a C project, you should copy the header filesrc/Randomizer_C.hto a desired location for your project.
- Input arguments: none
- Output: a
Randomizerinstance. - Default constructor method that sets the
Randomizer's root seed to the value of 1. The MINSTD algorithm is applied to the root seed once to generate the branching seed.
- Input arguments:
uint32_t input_seed: the initial root seed value.
- Output: a
Randomizerinstance. - A constructor method that takes an initial seed value that is set to
Randomizer's root seed. The MINSTD algorithm is applied to the root seed once to generate the branching seed.
- Input arguments: none
- Output: none
- This method applies the MINSTD algorithm to the current root seed to generate the next root seed value.
- Input arguments: none
- Output: none
- This method applies the inverse MINSTD algorithm to the current root seed to generate the previous root seed value.
- Input arguments: none
- Output: current root seed value.
- Input arguments:
- Output: current branching seed value.
- The branching seed value is updated every time by applying the MINSTD algorithm when any of the generator methods are invoked.
- Input arguments: none
- Output: a pseudo-random boolean value.
- This generator method returns a pseudo-random boolean value.
- Input arguments:
size_t out_str_length: the length of the string in number of characters to be generated.const char* dictionary: source string to pick characters from.
- Output: the output string of length
out_str_length. - If the input argument is
dictionaryisnullptr, the method will the following default source:!\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_``abcdefghijklmnopqrstuvwxyz{|}~
- Input arguments:
size_t out_str_length: the length of the string in number of characters to be generated.std::string& dictionary: reference to a source string to pick characters from.
- Output: the output string of length
out_str_length. - This is method calls
std::string gen_string(size_t out_str_length, const char* dictionary)to generate the pseudo-random string of lengthout_str_length.
- Input arguments: none
- Output: a floating-point value of type
Twithin the range [0.0, 1.0). - This method allows specifying the data type for the return floating-point value.
- Input arguments:
T lower: lower boundary for the range to generate floating-point value.T upper: upper boundary for the range to generate floating-point value.
- Output: the output floating-point value of type
Twithin the range specified by the method arguments. - This method returns a pseudo-random floating-point value of type
Twithin the desired range.
- Input arguments: none
- Output: the output integer value.
- This method allows specifying the data type for the return integer value.
- Input arguments:
T lower: lower boundary for the range to generate integer value.T upper: upper boundary for the range to generate integer value.
- Output: the output integer value.
- This method allows specifying the data type for the lower range, upper range, and return integer values.
- Input arguments:
T* array: a pointer to an array of elements of typeT.size_t n_elements: number of elements in the array.
- Output: The method returns 0 if the shuffle operation was successful. Otherwise, a value of -1 is returned if the
T* arrayargument isnullptrorsize_t n_elementsis 0. - This method performs the Fisher-Yates shuffling algorithm in place over an array of elements of type
T.
- Input arguments:
uint32_t input_seed: the initial root seed value.
- Output: a pointer to
Randomizer_Cobject. - This function calls the
Randomizerconstructor methodRandomizer(uint32_t input_seed).
- Input arguments:
Randomizer_C* rndc: a pointer to aRandomizer_C*object.
- Output: returns 0 if the delete operation was successful. Returns -1 if
rndcisNULL. - This method calls the
Randomizer's destructor method.
- Input arguments:
Randomizer_C* rndc: a pointer to aRandomizer_C*object.
- Output: none
- This function calls the
Randomizermethodvoid root_seed_next().
- Input arguments:
Randomizer_C* rndc: a pointer to aRandomizer_C*object.
- Output: none
- This function calls the
Randomizermethodvoid root_seed_prev().
- Input arguments:
Randomizer_C* rndc: a pointer to aRandomizer_C*object.
- Output: current root seed value.
- This function calls the
Randomizermethoduint32_t get_root_seed().
- Input arguments:
Randomizer_C* rndc: a pointer to aRandomizer_C*object.
- Output: current branching seed value.
- This function calls the
Randomizermethoduint32_t get_branching_seed().
- Input arguments:
Randomizer_C* rndc: a pointer to aRandomizer_C*object.
- Output: a pseudo-random boolean value.
- This function calls the
Randomizermethodbool gen_bool().
int Randomizer_C_gen_string(Randomizer_C* rndc, char* output_str, size_t out_str_length, const char* dictionary)
- Input arguments:
Randomizer_C* rndc: a pointer to aRandomizer_C*object.char* output_str: a pointer to the buffer to be populated with pseudo-random string.size_t out_str_length: the length of the string in number of characters to be generated.const char* dictionary: source string to pick characters from.
- Output: return 0 if successful generating a pseudo-random string given the arguments provided. Return -1 if
output_stris aNULLpointer. - This function calls the
Randomizermethodstd::string gen_string(size_t out_str_length, const char* dictionary).
- Input arguments:
Randomizer_C* rndc: a pointer to aRandomizer_C*object.
- Output: the output floating-point value within the range [0.0, 1.0).
- This function calls the
Randomizermethodtemplate<typename T> T gen_float().
- Input arguments:
Randomizer_C* rndc: a pointer to aRandomizer_C*object.float lower: lower boundary for the range to generate floating-point value.float upper: upper boundary for the range to generate floating-point value.
- Output: the output floating-point value within the range specified by the function arguments.
- This function calls the
Randomizermethodtemplate<typename T> T gen_float_range(T lower, T upper).
- Input arguments:
Randomizer_C* rndc: a pointer to aRandomizer_C*object.
- Output: the output floating-point value of type
doublewithin the range [0.0, 1.0). - This function calls the
Randomizermethodtemplate<typename T> T gen_float().
- Input arguments:
Randomizer_C* rndc: a pointer to aRandomizer_C*object.double lower: lower boundary for the range to generate floating-point value of typedouble.double upper: upper boundary for the range to generate floating-point value of typedouble.
- Output: the output floating-point value within the range specified by the function arguments.
- This function calls the
Randomizermethodtemplate<typename T> T gen_float_range(T lower, T upper).
- Input arguments:
Randomizer_C* rndc: a pointer to aRandomizer_C*object.
- Output: the output integer value.
- This function calls the
Randomizermethodtemplate<typename T> T gen_integral(). - The returned value is a data type
uint64_t.
- Input arguments:
Randomizer_C* rndc: a pointer to aRandomizer_C*object.uint64_t lower: lower boundary for the range to generate integer value.uint64_t upper: upper boundary for the range to generate integer value.
- Output: the output integer value.
- This function calls the
Randomizermethodtemplate<typename T> T gen_integral_range(T lower, T upper). - The returned value is a data type
uint64_t.
- Input arguments:
Randomizer_C* rndc: a pointer to aRandomizer_C*object.void* array: a pointer to an array of elements.size_t n_elements: number of elements in the array.size_t elem_size: byte-size of a single element.
- Output: The function returns 0 if the shuffle operation was successful. Otherwise, a value of -1 is returned if the
T* arrayargument isnullptrorsize_t n_elementsis 0. - This function implements the Fisher-Yates shuffling algorithm and does not call the
RandomizerC++ shuffle method to perform this operation.
- Refactored
double gen_double_not_nan()totemplate<typename T> T gen_float(). - Refactored
double gen_double_not_nan_range(double lower, double upper)totemplate<typename T> T gen_float_range(T lower, T upper). - Refactored
double Randomizer_C_gen_double_not_nan(Randomizer_C*)tofloat Randomizer_C_gen_float(Randomizer_C*). - Refactored
double Randomizer_C_gen_double_not_nan_range(Randomizer_C*, double, double)tofloat Randomizer_C_gen_float_range(Randomizer_C*, float, float). - Defined function
double Randomizer_C_gen_double(Randomizer_C*). - Defined function
double Randomizer_C_gen_double_range(Randomizer_C*, double, double). gen_float()generates a float value of typeTwithin the range [0.0, 1.0).
- Adding
#include <stdlib.h>toRandomizer_C.h. - Miscellaneous fixes and code clean up.
- Move
int Randomizer_C_shuffle(Randomizer_C*, void*, size_t, size_t)definition toRandomizer.cpp.
- Removed singleton implementation for
Randomizerclass allowing multiple instances to be created in a program. - Renaming
testing/Main.cpptotesting/RandomizerExample.cpp. - Updates to
testing/RandomizerExample.cppreflecting changes to removal of singleton implementation. - Definition of API for integration with C projects, including the following functions:
Randomizer_C* Randomizer_C_init(uint32_t)int Randomizer_C_delete(Randomizer_C*)void Randomizer_C_root_seed_next(Randomizer_C*)void Randomizer_C_root_seed_prev(Randomizer_C*)uint32_t Randomizer_C_get_root_seed(Randomizer_C*)uint32_t Randomizer_C_get_branching_seed(Randomizer_C*)bool Randomizer_C_gen_bool(Randomizer_C*)int Randomizer_C_gen_string(Randomizer_C*, char*, size_t, const char*)double Randomizer_C_gen_double_not_nan(Randomizer_C*)double Randomizer_C_gen_double_not_nan_range(Randomizer_C*, double, double)uint64_t Randomizer_C_gen_integral(Randomizer_C*)uint64_t Randomizer_C_gen_integral_range(Randomizer_C*, uint64_t, uint64_t)int Randomizer_C_shuffle(Randomizer_C*, void*, size_t, size_t)
- Miscellaneous fixes and code clean up.
shuffle(T, size_t)does not need to know element size.- Use
std::swapinshuffle(T, size_t)for swapping elements in array.
- Added method
get_root_seed(). - Added method
get_branching_seed(). - Added method
shuffle(void*, size_t, size_t)that implements variation of the Fisher-Yates shuffling algorithm. - Added wrapper method
shuffle(std::vector<T>&)that accepts anstd::vectorand invokesshuffle(void*, size_t, size_t).
- Removed word
randomfrom generation method names. - Update method names for creating and ending Randomizer instances.
- Updated
gen_string(size_t, std::string&);generate an output string restricted to characters present in astd::stringdictionary argument. - Added variation of
gen_string(size_t, const char*);to allow dictionary to be of typeconst char*. - Added
gen_bool()method.
- Initial release.