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

Is it possible to make randomUniform more efficient? #43

Open
sofian opened this issue Jul 24, 2012 · 0 comments
Open

Is it possible to make randomUniform more efficient? #43

sofian opened this issue Jul 24, 2012 · 0 comments
Labels

Comments

@sofian
Copy link
Owner

sofian commented Jul 24, 2012

The problem: randomUniform() performs two casts and one division.
Then randomUniform(float) version adds a multiplication to that.
Then randomUniform(float, float) adds yet another multiplication.

Maybe we should rewrite:

float randomUniform() {
  return randomUniform(0, 1);
}

float randomUniform(float h) {
  return randomUniform(0, h);
}

float randomUniform(float a, float b) {
  return ((float)random() / (float)
#ifdef RANDOM_MAX
      RANDOM_MAX
#else
      RAND_MAX
#endif
      * (b - a) + a);
}

Would require more calculations but less size.

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

No branches or pull requests

1 participant