Skip to content

Random function from WMath is biased #2467

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

Closed
lesept777 opened this issue Feb 16, 2019 · 0 comments
Closed

Random function from WMath is biased #2467

lesept777 opened this issue Feb 16, 2019 · 0 comments

Comments

@lesept777
Copy link

As coded below in Math.cpp, the random number is biased

long random(long howbig)
{
if(howbig == 0) {
return 0;
}
return esp_random() % howbig;
}

esp_random provides a 32 bit random integer so a number between 0 and 4294967295.
Returning a modulo number is biased. For example if howbig is 100, then all numbers between 0 and 95 have the same probability but numbers between 96 and 99 have a lower probability.

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

No branches or pull requests

1 participant