Fix invalid-too-large numbers being generated

This commit is contained in:
Stephen Seo 2024-04-16 18:42:16 +09:00
parent cea1bb5248
commit 6db258f59f
2 changed files with 14 additions and 3 deletions

View file

@ -1,6 +1,6 @@
COMMON_CXXFLAGS = -Wall -Wextra -Wpedantic -std=c++20
ifdef DEBUG
CXXFLAGS = -O0 -g ${COMMON_CXXFLAGS}
CXXFLAGS = -Og -g ${COMMON_CXXFLAGS}
else
CXXFLAGS = -O3 ${COMMON_CXXFLAGS}
endif

View file

@ -403,8 +403,19 @@ int main(int argc, char **argv) {
{
std::default_random_engine r_eng(std::chrono::steady_clock::now().time_since_epoch().count());
if(!isAlt && randomizeDigits) {
std::uniform_int_distribution<unsigned int> d_dist(1, digits);
unsigned int min_digits = 0;
for (unsigned long long min_copy = min; min_copy > 0; min_copy /= 10) {
++min_digits;
}
if (min_digits == 0) {
min_digits = 1;
}
if (min_digits < digits) {
std::uniform_int_distribution<unsigned int> d_dist(min_digits, digits);
digits = d_dist(r_eng);
} else {
digits = min_digits;
}
}
std::uniform_int_distribution<unsigned long long> r_dist(
min,