Skip to content

Commit

Permalink
Ensure that the first digit of a randomly generated BigInt is non-zero
Browse files Browse the repository at this point in the history
closes #40
  • Loading branch information
seldonwilson authored and faheel committed Jun 2, 2019
1 parent 5e3a130 commit f1fb18d
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions include/functions/random.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ BigInt big_random(size_t num_digits = 0) {

BigInt big_rand;
big_rand.value = ""; // clear value to append digits

// ensure that the first digit is non-zero
big_rand.value += std::to_string(1 + rand_generator() % 9);

while (big_rand.value.size() < num_digits)
big_rand.value += std::to_string(rand_generator());
if (big_rand.value.size() != num_digits)
Expand Down

0 comments on commit f1fb18d

Please sign in to comment.