Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure that the first digit of a randomly generated BigInt is non-zero #43

Merged
merged 2 commits into from
Jun 2, 2019

Conversation

seldonwilson
Copy link
Contributor

@seldonwilson seldonwilson commented May 25, 2019

Generates the first digit of a random BigInt to be a value from one to nine, inclusive, guaranteeing there will be no leading zeros.

Closes #40.

…ndom BigInt which contained leading zeros.
@faheel faheel changed the title Closes #40 Ensure that the first digit of a randomly generated BigInt is non-zero Jun 2, 2019
@@ -32,6 +32,9 @@ BigInt big_random(size_t num_digits = 0) {

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

// ensure first digit is non-zero
big_rand.value += std::to_string(rand_generator() % 8 + 1);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The expression should be be 1 + rand_generator() % 9.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow, I'm a bozo. I'll fix that.

First digit would only be [1, 8], now it will be [1,9]
Copy link
Contributor Author

@seldonwilson seldonwilson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it should be fixed. Sorry, I'm new to using GitHub for pull requests.

@faheel faheel merged commit 55cc05c into faheel:master Jun 2, 2019
@faheel
Copy link
Owner

faheel commented Jun 2, 2019

@seldonwilson Thank you for contributing!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

big_random might return a BigInt having a value with a leading 0
2 participants