From d16656919753438a57a32f9ad6ba972c25d66b11 Mon Sep 17 00:00:00 2001 From: Sebastiano Tronto Date: Sun, 9 Feb 2025 19:38:26 +0100 Subject: Added random number generator for bigint --- bigint.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'bigint.h') diff --git a/bigint.h b/bigint.h index 9287fda..096ed9c 100644 --- a/bigint.h +++ b/bigint.h @@ -3,6 +3,7 @@ #include #include +#include #include constexpr uint64_t abs64(int64_t); @@ -123,6 +124,18 @@ public: constexpr BigInt operator/=(const BigInt& z) { return *this = *this / z; } constexpr BigInt operator%=(const BigInt& z) { return *this = *this % z; } + static BigInt random(BigInt r) { + std::random_device rd; + std::default_random_engine rng(rd()); + std::uniform_int_distribution distribution(0, M-1); + + BigInt ret; + for (uint64_t i = 0; i < D; i++) + ret.digits[i] = distribution(rng); + + return ret % r; + } + friend std::ostream& operator<<(std::ostream& os, const BigInt& z) { if (z == 0) { os << "0"; -- cgit v1.3