Skip to content

Commit ae20cd9

Browse files
authored
Merge pull request #304 from schmouk/release-2-1
Release 2-1
2 parents 55a8f74 + 8a2c08f commit ae20cd9

File tree

115 files changed

+483
-298
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

115 files changed

+483
-298
lines changed

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1206,3 +1206,13 @@ In ACM Transactions on Mathematical Software, Volume 44, Issue 3, April 2018, Ar
12061206
Also published in arXiv, March 2022 (11 pages)
12071207
Last reference: arXiv:1505.06582v6 [cs.DS] 20 Nov 2017, see [https://arxiv.org/pdf/1505.06582](https://arxiv.org/pdf/1505.06582).
12081208
DOI: https://doi.org/10.1145/3159444, https://doi.org/10.48550/arXiv.1505.06582
1209+
1210+
1211+
**[12]** Marsaglia, G. 1972.
1212+
*The structure of linear congruential sequences.*
1213+
In Applications of Number Theory to Numerical Analysis, S. K. Zaremba, Ed. Academic Press, 249–285.
1214+
1215+
1216+
**[13]** Brown, F. B. and Nagaya, Y. 2002.
1217+
*The MCNP5 random number generator.*
1218+
Tech. rep. LA-UR-02-3782, Los Alamos National Laboratory

c++11/baseclasses/basemrg31.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,11 @@ SOFTWARE.
5353
*
5454
* See Mrg287 for a short period MR-Generator (2^287, i.e. 2.49e+86) with low
5555
* computation time but 256 integers memory consumption (2^32 modulus calculations).
56+
*
5657
* See Mrg1457 for a longer period MR-Generator (2^1457, i.e. 4.0e+438) and longer
5758
* computation time (2^31-1 modulus calculations) but less memory space consumption
5859
* (i.e. 47 integers).
60+
*
5961
* See Mrg49507 for a far longer period (2^49_507, i.e. 1.2e+14_903) with low
6062
* computation time too (31-bits modulus) but use of more memory space (1_597
6163
* integers).

c++11/baseclasses/basemrg32.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,11 @@ SOFTWARE.
5353
*
5454
* See Mrg287 for a short period MR-Generator (2^287, i.e. 2.49e+86) with low
5555
* computation time but 256 integers memory consumption (2^32 modulus calculations).
56+
*
5657
* See Mrg1457 for a longer period MR-Generator (2^1457, i.e. 4.0e+438) and longer
5758
* computation time (2^31-1 modulus calculations) but less memory space consumption
5859
* (i.e. 47 integers).
60+
*
5961
* See Mrg49507 for a far longer period (2^49_507, i.e. 1.2e+14_903) with low
6062
* computation time too (31-bits modulus) but use of more memory space (1_597
6163
* integers).

c++11/baseclasses/basepcg.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@ SOFTWARE.
3838
*
3939
* x(i) = (a*x(i-1) + c) mod m
4040
*
41-
* PCGs associate to this recurrence a permutation of a subpart o f the bits
42-
* of the internal state of the PRNG. The output of PCGs is this permutated
43-
* subpart of its internal state, leading to a very large enhancement of the
44-
* randomness of these algorithms compared with the LCGs one.
41+
* PCGs associate to this recurrence a permutation of a subpart of their
42+
* internal state bits. The output of PCGs is this permutated subpart of its
43+
* internal state, leading to a very large enhancement of the randomness of
44+
* these algorithms compared with the LCGs one.
4545
*
4646
* These PRNGs have been tested with TestU01 by the authors and have shown to
4747
* pass all tests (about TestU01, see Pierre L'Ecuyer and Richard Simard

c++11/baseclasses/baserandom.h

Lines changed: 66 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -43,28 +43,70 @@ SOFTWARE.
4343
//===========================================================================
4444
/** @brief This is the base class for all pseudo-random numbers generators.
4545
*
46-
* See FastRand32 for a 2^32 (i.e. 4.3e+9) period LC-Generator and FastRand63 for a
47-
* 2^63 (i.e. about 9.2e+18) period LC-Generator with low computation time.
46+
* See Cwg64 for a minimum 2^70 (i.e. about 1.18e+21) period Collatz-Weyl Generator
47+
* with low computation time, medium period, 64- bits output values and very good
48+
* randomness characteristics.
49+
* See Cwg128_64 for a minimum 2^71 (i.e. about 2.36e+21) period C-W Generator with
50+
* with very low computation time, medium period, 64-bits output values and very
51+
* good randomness characteristics.
52+
* See Cwg128 for a minimum 2^135 (i.e. about 4.36e+40) period C-W generator with
53+
* very low computation time, medium period, 64- bits output values and very good
54+
* randomness characteristics.
4855
*
49-
* See FastRand63 for a 2^63 (i.e. about 9.2e+18) period LC-Generator with low
50-
* computation time also, longer period and quite better randomness characteristics
51-
* than for FastRand32.
56+
* See FastRand32 for a 2^32 (i.e. 4.29e+9) period Linear Congruential Generator and
57+
* FastRand63 for a 2^63 (i.e. about 9.2e+18) period LC-Generator with very low
58+
* computation time and very low memory consumption (resp. 1 and 2 32-bits integers).
5259
*
53-
* See MRGRand287, MRGRand1457 and MRGRand49507 for long periods MR-Generators (resp.
54-
* 2^287, 2^1,457 and 2^49,507, i.e. 2.49e+86, 4.0e+438 and 1.2e+14,903) with low
55-
* computation time but resp. 256, 47 and 1,597 integers memory consumption. Output
56-
* values are coded on resp. 32-, 31- and 31- bits.
60+
* See LFibRand78, LFibRand116, LFibRand668 and LFibRand1340 for large period Lagged
61+
* Fibonacci Generators (resp. 2^78, 2^116, 2^668 and 2^1340 periods, i.e. resp.
62+
* 3.0e+23, 8.3e+34, 1.2e+201 and 2.4e+403 periods) while same computation time and
63+
* far higher precision (64-bits calculations) but memory consumption (resp. 17, 55,
64+
* 607 and 1279 32-bits integers).
5765
*
58-
* See LFibRand78, LFibRand116, LFibRand668 and LFibRand1340 for long period LFib
59-
* generators (resp. 2^78, 2^116, 2^668 and 2^1340 periods, i.e. resp. 3.0e+23,
60-
* 8.3e+34, 1.2e+201 and 2.4e+403 periods) while same computation time and far higher
61-
* precision (64-bits calculations) but memory consumption (resp. 17, 55, 607 and
62-
* 1279 integers).
63-
*
64-
* See Xoroshiro256, Xoroshiro512, Xoroshiro1024 for long period generators (resp.
65-
* 2^256, 2^512 and 2^1024 periods, i.e. resp. 1.16e+77, 1.34e+154 and 1.80e+308
66-
* periods), 64-bits precision calculations and short memory consumption (resp. 4,
67-
* 8 and 16 integers coded on 64 bits).
66+
* See Melg607 for a large period Maximally Equidistributed F2-Linear Generator
67+
* (2^607, i.e. 5.31e+182) with medium computation time and the equivalent of 21 32-
68+
* bits integers memory little consumption.
69+
* See Melg19937 for alarger period MELG-Generator (2^19,937, i.e. 4.32e+6001), same
70+
* computation time and equivalent of 625 integers memory consumption.
71+
* See Melg44497 for a very large period (2^44,497, i.e. 8.55e+13,395) with similar
72+
* computation time but use of even more memory space (equivalent of 1,393 32-bits
73+
* integers). This is the longest period version proposed in paper [11].
74+
*
75+
* See Mrg287 for a short period Multiple Recursive Generator (2^287, i.e. 2.49e+86)
76+
* with low computation time but 256 32-bits integers memory consumption.
77+
* See Mrg1457 for a longer period MR-Generator (2^1457, i.e. 4.0e+438) and longer
78+
* computation time (2^31-1 modulus calculations) but less memory space consumption
79+
* (32-bits 47 integers).
80+
* See Mrg49507 for a far larger period MR-Generator (2^49507, i.e. 1.2e+14903) with
81+
* low computation time too (31-bits modulus) but use of more memory space (1597
82+
* 32-bits integers).
83+
*
84+
* See Pcg64_32, Pcg128_64 and Pcg1024_32 for Permuted Congruential Generators with
85+
* medium to very large periods, very low computation time, and for very low memory
86+
* consumption for the two first (resp. 4, 8 and 1,026 times 32-bits). Associated
87+
* periods are resp. 2^64, 2^128 and 2^32830, i.e. 1.84e+19, 3.40e+38 and 6.53e+9882.
88+
* These PRNGs provide multi-streams and jump ahead features. Since they all are
89+
* exposing only a part of their internal state, they are difficult to reverse and
90+
* to predict.
91+
*
92+
* See Squares32 for a counter-based middle-square random number generator with 2^64
93+
* (i.e. about 1.84e+19) period, low computation time, 32-bits output values and very
94+
* good randomness characteristics.
95+
* See Squares64 for a 2^64 (i.e. about 1.84e+19) period PRNG with low computation
96+
* time, medium period, 64-bits output values and very good randomness
97+
* characteristics. Caution: this 64-bits version should not pass the birthday test,
98+
* which is a randomness issue, while this is not mentionned in the original paper.
99+
*
100+
* See Well512a, Well1024a, Well19937c and Well44479b for large to very large period
101+
* generators (resp. 2^512, 2^1024, 2^19937 and 2^44479 periods, i.e. resp. 1.34e+154,
102+
* 2.68e+308, 4.32e+6001 and 1.51e+13466 periods), a little bit longer computation
103+
* times but very quick escaping from zeroland. Memory consumption is resp. 32, 64,
104+
* 624 and 1391 32-bits integers.
105+
*
106+
* See Xoroshiro256, Xoroshiro512, Xoroshiro1024 for long period generators (resp.
107+
* 2^256, 2^512 and 2^1024 periods, i.e. resp. 1.16e+77, 1.34e+154 and 1.80e+308
108+
* periods), 64-bits precision calculations and short memory consumption (resp. 4,
109+
* 8 and 16 integers each coded on 64 bits.
68110
*
69111
* Furthermore this class and all its inheriting sub-classes are callable. Example:
70112
* @code
@@ -80,7 +122,7 @@ SOFTWARE.
80122
* std::cout << diceRoll.randint(1, 6) << std::endl; // prints also a uniform roll within range {1, ..., 6}
81123
* @endcode
82124
*
83-
* Conforming to the former Python version of this library (CppRandLib), next methods
125+
* Conforming to the former Python version of this library (i.e. PyRandLib), next methods
84126
* are available - built-in function in Python module 'random':
85127
* |
86128
* | betavariate(alpha, beta)
@@ -668,7 +710,6 @@ class BaseRandom
668710
inline void setstate(const StateT& new_internal_state, const double gauss_next) noexcept;
669711

670712

671-
672713
/** @brief Returns the current internal state value. */
673714
inline const state_type state() const noexcept;
674715

@@ -1661,10 +1702,10 @@ inline void BaseRandom<StateT, OutputT, OUTPUT_BITS>::seed(const utils::UInt128&
16611702
template<typename StateT, typename OutputT, const std::uint8_t OUTPUT_BITS>
16621703
inline void BaseRandom<StateT, OutputT, OUTPUT_BITS>::seed(const double seed_)
16631704
{
1664-
if (seed_ < 0.0 || 1.0 <= seed_)
1705+
if (0.0 <= seed_ && seed_ <= 1.0)
1706+
seed(std::uint64_t(seed_ * double(0xffff'ffff'ffff'ffffULL)));
1707+
else
16651708
throw FloatValueRange01Exception();
1666-
1667-
seed(std::uint64_t(seed_ * double(0xffff'ffff'ffff'ffffULL)));
16681709
}
16691710

16701711
//---------------------------------------------------------------------------
@@ -1743,7 +1784,7 @@ const double BaseRandom<StateT, OutputT, OUTPUT_BITS>::expovariate(const double
17431784
throw ExponentialZeroLambdaException();
17441785

17451786
const double u{ uniform() };
1746-
if (u < 1.0) // should always happen, let's check for it nevertheless
1787+
if (u < 1.0) // should always happen, let's check it nevertheless
17471788
return -std::log(1.0 - u) / lambda;
17481789
else
17491790
return 0.0;

c++11/baseclasses/basewell.h

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,21 +51,24 @@ SOFTWARE.
5151
* zeroland.
5252
*
5353
* Notice: the algorithm in the 4 different versions implemented here has been coded
54-
* here as a direct implementation of their descriptions in the initial paper
55-
* "Improved Long-Period Generators Based on Linear Recurrences Modulo 2", François
56-
* PANNETON and Pierre LECUYER (Université de Montréal) and Makoto MATSUMOTO
57-
* (Hiroshima University), in ACM Transactions on Mathematical Software, Vol. 32,
58-
* No. 1, March 2006, Pages 116.
54+
* as a direct implementation of their descriptions in the initial paper "Improved
55+
* Long-Period Generators Based on Linear Recurrences Modulo 2", François PANNETON
56+
* and Pierre L'ECUYER (Université de Montréal) and Makoto MATSUMOTO (Hiroshima
57+
* University), in ACM Transactions on Mathematical Software, Vol. 32, No. 1, March
58+
* 2006, Pages 1-16.
5959
* (see https://www.iro.umontreal.ca/~lecuyer/myftp/papers/wellrng.pdf).
6060
* So, only minimalist optimization has been coded, with the aim at easing the
6161
* verification of its proper implementation.
6262
*
6363
* See Well512a for a large period WELL-Generator (2^512, i.e. 1.34e+154) with low
6464
* computation time and 16 integers memory little consumption.
65+
*
6566
* See Well1024a for a longer period WELL-Generator (2^1,024, i.e. 1.80e+308), same
6667
* computation time and 32 integers memory consumption.
68+
*
6769
* See Well199937c for a far longer period (2^19,937, i.e. 4.32e+6,001) with similar
6870
* computation time but use of more memory space (624 integers).
71+
*
6972
* See Well44497b for a very large period (2^44,497, i.e. 15.1e+13,466) with similar
7073
* computation time but use of even more memory space (1,391 integers).
7174
*

c++11/internalstates/extendedstate.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ SOFTWARE.
3434

3535

3636
//===========================================================================
37-
/** @brief The internal state of many Pseudo Random Numbers Generators. */
37+
/** @brief The internal extended state of some Pseudo Random Numbers Generators. */
3838
template<typename StateType, typename ExtendedValueType, const size_t EXTENDED_SIZE>
3939
struct ExtendedState
4040
{
@@ -48,7 +48,7 @@ struct ExtendedState
4848

4949
inline ExtendedState() noexcept; //!< Empty constructor
5050

51-
inline void seed(const std::uint64_t seed_) noexcept; //!< state and external state inbitialization
51+
inline void seed(const std::uint64_t seed_) noexcept; //!< state and external state initialization
5252

5353
};
5454

c++11/mrg1457.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ SOFTWARE.
6060
*
6161
* See Mrg287 for a short period MR-Generator (2^287, i.e. 2.49e+86) with low
6262
* computation time but 256 integers memory consumption (2^32 modulus calculations).
63+
*
6364
* See Mrg49507 for a far longer period (2^49,507, i.e. 1.2e+14,903) with low
6465
* computation time too (31-bits modulus) but use of more memory space (1,597
6566
* integers).

c++11/mrg287.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ SOFTWARE.
7777
* See Mrg1457 for a longer period MR-Generator (2^1457, i.e. 4.0e+438) and longer
7878
* computation time (2^31-1 modulus calculations) but less memory space consumption
7979
* (i.e. 47 integers).
80+
*
8081
* See Mrg49507 for a far longer period (2^49,507, i.e. 1.2e+14,903) with low
8182
* computation time too (31-bits modulus) but use of more memory space (1,597
8283
* integers).

c++11/mrg49507.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,15 @@ const Mrg49507::output_type Mrg49507::next() noexcept
107107
const std::uint32_t k7{ (index < 7) ? (index + SEED_SIZE) - 7 : index - 7 };
108108

109109
// evaluates current value and modifies internal state
110+
const std::int64_t s = std::int64_t(_internal_state.state.list[k7]) + std::int64_t(_internal_state.state.list[index]);
111+
const std::int64_t v1 = Mrg49507::_MULT * s;
112+
const std::int64_t v2 = v1 % _MODULO;
113+
const std::uint64_t value_ = v2 & 0x7fff'ffff;
114+
110115
const std::uint64_t value{
111-
(0xffff'ffff'fdff'ff80ull * //i.e. (-2^25 - 2^7), or -67'108'992
112-
std::uint64_t(_internal_state.state.list[k7] + _internal_state.state.list[index])
116+
//(0xffff'ffff'fdff'ff80ull * //i.e. (-2^25 - 2^7), or -67'108'992
117+
(Mrg49507::_MULT * //i.e. (-2^25 - 2^7)
118+
std::int64_t(_internal_state.state.list[k7] + _internal_state.state.list[index])
113119
) % _MODULO
114120
};
115121
_internal_state.state.list[index] = std::uint32_t(value);

0 commit comments

Comments
 (0)