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

Add float support for generate_range() #27

Open
aricasas opened this issue Jul 8, 2021 · 1 comment
Open

Add float support for generate_range() #27

aricasas opened this issue Jul 8, 2021 · 1 comment

Comments

@aricasas
Copy link

aricasas commented Jul 8, 2021

It would be cool to add float support to this function. So that we can generate random floats with custom ranges.

Example:

let rng = nanorand::tls_rng();
let rand_num: f64 = rng.generate_range(-3.0..5.5);
@aricasas
Copy link
Author

I found how rand implements float ranges, I think, which could be useful:
https://docs.rs/rand/0.8.4/src/rand/distributions/uniform.rs.html#788-997

In essence, they generate a number [0,1), then multiply by the size of the range, and finally add the lower bound. But they also handle a ton of edge cases in their code, so that makes it more complicated.

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