initial commit
This commit is contained in:
36
include/ReUnirand/unirand.hpp
Normal file
36
include/ReUnirand/unirand.hpp
Normal file
@@ -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
|
Reference in New Issue
Block a user