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

Misleading documentation regarding distributions::Uniform #388

Closed
bgamari opened this issue Apr 11, 2018 · 6 comments
Closed

Misleading documentation regarding distributions::Uniform #388

bgamari opened this issue Apr 11, 2018 · 6 comments

Comments

@bgamari
Copy link

bgamari commented Apr 11, 2018

The first example in the documentation of distributions::Uniform is,

use rand::{NewRng, SmallRng, Rng};
use rand::distributions::Uniform;

let val: f32 = SmallRng::new().sample(Uniform);
println!("f32 from [0,1): {}", val);

The last print directly the earlier discussion of this distribution's semantics; namely that it draws from the open set (0,1).

Moreover, the documentation gives no guidance for users who want the usual half-open uniform distribution drawing from [0,1).

@bgamari
Copy link
Author

bgamari commented Apr 12, 2018

Presumably one is supposed to use rand::distributions::range::Range for the half-open distribution?

@pitdicker
Copy link
Contributor

Good point. See #392.

@dhardy
Copy link
Member

dhardy commented Apr 12, 2018

Well spotted.

If there is some specific need for the half-open range it may be worth revisiting our decision to use an open range by default (though maybe more documentation is all that is needed). @bgamari your thoughts on this / reason for wanting a half-open range?

@bgamari
Copy link
Author

bgamari commented Apr 16, 2018

Indeed, documentation describing the motivation for the open range would be welcome. I'll admit that I found this a bit surprising.

In my case I needed to generate a variate corresponding to an angle, (i.e. on [0, 2*pi)). My first intuition was to scale a standard uniform variate, but after noticing that the standard variate was open I realized I would be better off using a uniform with explicit range.

@dhardy
Copy link
Member

dhardy commented Apr 16, 2018

If you want to know why see this comment or the whole thread. I'm still uncertain whether this is a good idea myself.

Range::new(0.0, 2.0 * f64::consts::PI) is probably what you want in this case anyway.

@vks
Copy link
Collaborator

vks commented Apr 17, 2018

I believe this was fixed with #392?

@dhardy dhardy closed this as completed Apr 17, 2018
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

4 participants