tmp/tmpf2apubk9/{from.md → to.md}
RENAMED
|
@@ -20,10 +20,11 @@ and a = b - (b - 1) / m. — *end note*]
|
|
| 20 |
|
| 21 |
The generation algorithm is given by GA(xᵢ) = y, where y is the value
|
| 22 |
produced as a result of advancing the engine’s state as described above.
|
| 23 |
|
| 24 |
``` cpp
|
|
|
|
| 25 |
template<class UIntType, size_t w, size_t s, size_t r>
|
| 26 |
class subtract_with_carry_engine {
|
| 27 |
public:
|
| 28 |
// types
|
| 29 |
using result_type = UIntType;
|
|
@@ -41,14 +42,27 @@ template<class UIntType, size_t w, size_t s, size_t r>
|
|
| 41 |
explicit subtract_with_carry_engine(result_type value);
|
| 42 |
template<class Sseq> explicit subtract_with_carry_engine(Sseq& q);
|
| 43 |
void seed(result_type value = default_seed);
|
| 44 |
template<class Sseq> void seed(Sseq& q);
|
| 45 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
// generating functions
|
| 47 |
result_type operator()();
|
| 48 |
void discard(unsigned long long z);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
};
|
|
|
|
| 50 |
```
|
| 51 |
|
| 52 |
The following relations shall hold: `0u < s`, `s < r`, `0 < w`, and
|
| 53 |
`w <= numeric_limits<UIntType>::digits`.
|
| 54 |
|
|
@@ -69,11 +83,11 @@ To set the values Xₖ, first construct `e`, a
|
|
| 69 |
linear_congruential_engine<result_type,
|
| 70 |
40014u,0u,2147483563u> e(value == 0u ? default_seed : value);
|
| 71 |
```
|
| 72 |
|
| 73 |
Then, to set each Xₖ, obtain new values z₀, …, zₙ₋₁ from n = ⌈ w/32 ⌉
|
| 74 |
-
successive invocations of `e`
|
| 75 |
$\left( \sum_{j=0}^{n-1} z_j \cdot 2^{32j}\right) \bmod m$.
|
| 76 |
|
| 77 |
*Complexity:* Exactly n ⋅ `r` invocations of `e`.
|
| 78 |
|
| 79 |
``` cpp
|
|
|
|
| 20 |
|
| 21 |
The generation algorithm is given by GA(xᵢ) = y, where y is the value
|
| 22 |
produced as a result of advancing the engine’s state as described above.
|
| 23 |
|
| 24 |
``` cpp
|
| 25 |
+
namespace std {
|
| 26 |
template<class UIntType, size_t w, size_t s, size_t r>
|
| 27 |
class subtract_with_carry_engine {
|
| 28 |
public:
|
| 29 |
// types
|
| 30 |
using result_type = UIntType;
|
|
|
|
| 42 |
explicit subtract_with_carry_engine(result_type value);
|
| 43 |
template<class Sseq> explicit subtract_with_carry_engine(Sseq& q);
|
| 44 |
void seed(result_type value = default_seed);
|
| 45 |
template<class Sseq> void seed(Sseq& q);
|
| 46 |
|
| 47 |
+
// equality operators
|
| 48 |
+
friend bool operator==(const subtract_with_carry_engine& x,
|
| 49 |
+
const subtract_with_carry_engine& y);
|
| 50 |
+
|
| 51 |
// generating functions
|
| 52 |
result_type operator()();
|
| 53 |
void discard(unsigned long long z);
|
| 54 |
+
|
| 55 |
+
// inserters and extractors
|
| 56 |
+
template<class charT, class traits>
|
| 57 |
+
friend basic_ostream<charT, traits>&
|
| 58 |
+
operator<<(basic_ostream<charT, traits>& os, const subtract_with_carry_engine& x);
|
| 59 |
+
template<class charT, class traits>
|
| 60 |
+
friend basic_istream<charT, traits>&
|
| 61 |
+
operator>>(basic_istream<charT, traits>& is, subtract_with_carry_engine& x);
|
| 62 |
};
|
| 63 |
+
}
|
| 64 |
```
|
| 65 |
|
| 66 |
The following relations shall hold: `0u < s`, `s < r`, `0 < w`, and
|
| 67 |
`w <= numeric_limits<UIntType>::digits`.
|
| 68 |
|
|
|
|
| 83 |
linear_congruential_engine<result_type,
|
| 84 |
40014u,0u,2147483563u> e(value == 0u ? default_seed : value);
|
| 85 |
```
|
| 86 |
|
| 87 |
Then, to set each Xₖ, obtain new values z₀, …, zₙ₋₁ from n = ⌈ w/32 ⌉
|
| 88 |
+
successive invocations of `e`. Set Xₖ to
|
| 89 |
$\left( \sum_{j=0}^{n-1} z_j \cdot 2^{32j}\right) \bmod m$.
|
| 90 |
|
| 91 |
*Complexity:* Exactly n ⋅ `r` invocations of `e`.
|
| 92 |
|
| 93 |
``` cpp
|