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

Fix dice rolling calculation #216

Merged
merged 1 commit into from
Nov 21, 2023
Merged

Conversation

lunakv
Copy link
Contributor

@lunakv lunakv commented Nov 18, 2023

The way individual dice rolls were created was incorrect.

If we calculate a roll of a d6 (d.sides == 6), we want to generate a random number between 0 and 5, then add one. However, since the range of rand.Intn isn't inclusive, calling rand.Intn(5) (which is what we're doing for a d6) can only produce numbers from 0 to 4, giving us a result between 1 and 5. This effectively means the highest value can never be rolled. The easiest way to test this is to roll some d2's, they'll always come out as one. (99d2 always results in a 99).

This PR fixes this off-by-one error by setting the correct upper limit.

@Fryyyyy Fryyyyy merged commit 45d991d into Fryyyyy:master Nov 21, 2023
2 checks passed
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.

2 participants