From 6e056e9a84c6cb1688f77cb4b8465a2df47a6faa Mon Sep 17 00:00:00 2001 From: rich Date: Sat, 1 Feb 2025 16:56:59 -0500 Subject: [PATCH] initial commit --- include/ReUnirand/unirand.hpp | 36 +++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 include/ReUnirand/unirand.hpp diff --git a/include/ReUnirand/unirand.hpp b/include/ReUnirand/unirand.hpp new file mode 100644 index 0000000..aac10ec --- /dev/null +++ b/include/ReUnirand/unirand.hpp @@ -0,0 +1,36 @@ +#ifndef REUNIRAND_UNIRAND_HPP +#define REUNIRAND_UNIRAND_HPP + +namespace ReUnirand { + + // Marsaglia's Universal Random Number Generator class. + // This class implements Marsaglia's UNI random number generator algorithm. + class MarsagliaUniRng { + public: + // Default constructor. + MarsagliaUniRng(); + + // Generates and returns a random floating-point number between 0 and 1. + float uni(); + + // Initialises the internal state using four seeds. + // The parameters i, j, k, and l should be positive integers. + void rstart(int i, int j, int k, int l); + + // Decomposes a single seed into four components and initialises the generator. + // The seed (ijkl) must be between 0 and 900,000,000. + void rinit(int ijkl); + + private: + static const int LEN_U = 98; // Length of the random values array. + float uni_u[LEN_U]; // Array holding the recent random numbers. + float uni_c; // Correction value to avoid periodicity. + float uni_cd; // Correction delta. + float uni_cm; // Correction modulus. + int uni_ui; // Current index in the array. + int uni_uj; // Secondary index in the array. + }; + +} // namespace ReUnirand + +#endif // REUNIRAND_UNIRAND_H