aboutsummaryrefslogtreecommitdiff
path: root/bigint.h
diff options
context:
space:
mode:
Diffstat (limited to 'bigint.h')
-rw-r--r--bigint.h13
1 files changed, 13 insertions, 0 deletions
diff --git a/bigint.h b/bigint.h
index 9287fda..096ed9c 100644
--- a/bigint.h
+++ b/bigint.h
@@ -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
8constexpr uint64_t abs64(int64_t); 9constexpr 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";