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

Fixed loaded dice #1

Merged
merged 1 commit into from
Dec 13, 2016
Merged

Fixed loaded dice #1

merged 1 commit into from
Dec 13, 2016

Conversation

Smartnor
Copy link
Contributor

This random number generator was used in a way that made it twice as likely to roll the highest number for any given die as any other number for that die.

The code :crypto.rand_uniform(0, n+1) increases the range of the uniform random number generator one higher than intended. The range extends from 0 up to and including num_sides.

So, Enum.at(die, index - 1) would give the highest result if index was zero. It would also give the highest result if index was num_sides. This would make the highest result twice as likely as any other since all of the others are generated uniformly.

This would skew the mean of the dice rolls higher than the true mean, hence loading the dice.

@ghost
Copy link

ghost commented Dec 13, 2016

This library ruined my video game.

@stocks29 stocks29 merged commit ae729bc into stocks29:master Dec 13, 2016
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