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

Helpers.cpp functions can produce non-uniformity #1

Open
ryandougherty opened this issue Mar 17, 2014 · 0 comments
Open

Helpers.cpp functions can produce non-uniformity #1

ryandougherty opened this issue Mar 17, 2014 · 0 comments

Comments

@ryandougherty
Copy link

double rand_float()
{
return rand() / (static_cast(RAND_MAX));
}

double rand_float(float min, float max)
{
return (max-min)*rand_float()+min;
}

int rand_int(int min,int max)
{
return (rand() % (max-min)) + min;
}

These functions in /simplega/helpers.cpp can give non-uniformity because of modding by an integer (see http://channel9.msdn.com/Events/GoingNative/2013/rand-Considered-Harmful for details as to why).

Proposition: use std::uniform_int_distribution and std::uniform_real_distribution to shape the random integers/floats being generated.

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