diff options
| author | Sebastiano Tronto <sebastiano@tronto.net> | 2025-02-09 19:38:26 +0100 |
|---|---|---|
| committer | Sebastiano Tronto <sebastiano@tronto.net> | 2025-02-09 19:39:13 +0100 |
| commit | d16656919753438a57a32f9ad6ba972c25d66b11 (patch) | |
| tree | e7b99259c2584d0c092b5044583571cce0a4918e /bigint.h | |
| parent | ece9b2e4c547c986fd9e2bb4b7d97287be5621fb (diff) | |
| download | zmodn-d16656919753438a57a32f9ad6ba972c25d66b11.tar.gz zmodn-d16656919753438a57a32f9ad6ba972c25d66b11.zip | |
Diffstat (limited to 'bigint.h')
| -rw-r--r-- | bigint.h | 13 |
1 files changed, 13 insertions, 0 deletions
| @@ -3,6 +3,7 @@ | |||
| 3 | 3 | ||
| 4 | #include <cstdint> | 4 | #include <cstdint> |
| 5 | #include <iostream> | 5 | #include <iostream> |
| 6 | #include <random> | ||
| 6 | #include <string_view> | 7 | #include <string_view> |
| 7 | 8 | ||
| 8 | constexpr uint64_t abs64(int64_t); | 9 | constexpr uint64_t abs64(int64_t); |
| @@ -123,6 +124,18 @@ public: | |||
| 123 | constexpr BigInt operator/=(const BigInt& z) { return *this = *this / z; } | 124 | constexpr BigInt operator/=(const BigInt& z) { return *this = *this / z; } |
| 124 | constexpr BigInt operator%=(const BigInt& z) { return *this = *this % z; } | 125 | constexpr BigInt operator%=(const BigInt& z) { return *this = *this % z; } |
| 125 | 126 | ||
| 127 | static BigInt random(BigInt r) { | ||
| 128 | std::random_device rd; | ||
| 129 | std::default_random_engine rng(rd()); | ||
| 130 | std::uniform_int_distribution<int> distribution(0, M-1); | ||
| 131 | |||
| 132 | BigInt ret; | ||
| 133 | for (uint64_t i = 0; i < D; i++) | ||
| 134 | ret.digits[i] = distribution(rng); | ||
| 135 | |||
| 136 | return ret % r; | ||
| 137 | } | ||
| 138 | |||
| 126 | friend std::ostream& operator<<(std::ostream& os, const BigInt<N, E>& z) { | 139 | friend std::ostream& operator<<(std::ostream& os, const BigInt<N, E>& z) { |
| 127 | if (z == 0) { | 140 | if (z == 0) { |
| 128 | os << "0"; | 141 | os << "0"; |
