{"action":"created","issue":{"url":"https://api.github.com/repos/dhardy/rand/issues/85","repository_url":"https://api.github.com/repos/dhardy/rand","labels_url":"https://api.github.com/repos/dhardy/rand/issues/85/labels{/name}","comments_url":"https://api.github.com/repos/dhardy/rand/issues/85/comments","events_url":"https://api.github.com/repos/dhardy/rand/issues/85/events","html_url":"https://github.com/dhardy/rand/issues/85","id":289964241,"number":85,"title":"discussion on uniform float distributions","user":{"login":"tspiteri","id":18604588,"avatar_url":"https://avatars0.githubusercontent.com/u/18604588?v=4","gravatar_id":"","url":"https://api.github.com/users/tspiteri","html_url":"https://github.com/tspiteri","followers_url":"https://api.github.com/users/tspiteri/followers","following_url":"https://api.github.com/users/tspiteri/following{/other_user}","gists_url":"https://api.github.com/users/tspiteri/gists{/gist_id}","starred_url":"https://api.github.com/users/tspiteri/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tspiteri/subscriptions","organizations_url":"https://api.github.com/users/tspiteri/orgs","repos_url":"https://api.github.com/users/tspiteri/repos","events_url":"https://api.github.com/users/tspiteri/events{/privacy}","received_events_url":"https://api.github.com/users/tspiteri/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":26,"created_at":"2018-01-19T12:44:31Z","updated_at":"2018-04-12T06:36:43Z","closed_at":null,"author_association":"NONE","body":"I've had a look at `FloatConversions` and `Uniform01`, `Closed01` and `Open01`. I'm not sure all the features should be there. Personally I would only provide the following two features, one from a generator perspective, and the other more from a distribution perspective:\r\n\r\n1. A way to generate a random number similar to the `next_f32` or `next_f64` in rand 0.4, and which is now in `FloatConversions::open_closed01_fixed`. I would not provide any of the other five functions in `FloatConversions` and think that if this is not sufficient, probably what is required is something from the uniform distribution. I prefer the situation with rand 0.4 here, where `next_f32` and `next_f64` are part of the generator.\r\n\r\n2. For the uniform distribution inside the `distributions` module, I would provide `Uniform01` only and remove `Closed01` and `Open01`, and for the implementation I would specify that it is equivalent to generating a floating-point number with arbitrarily large precision with a continuous uniform distribution in the range [0,1], and rounding.\r\n\r\nNumber 1 is  I think the most common way to simply generate a random float, and it always produces *m* bits of randomness where *m* is the number of mantissa bits. The output is a multiple of ɛ that is < 1, and every possible outcome has a probability of occurrence = ɛ. This is what I would expect from a generator. It is very similar to generating integers, except that the randomness is in the mantissa only.\r\n\r\nNumber 2 is from the distribution point of view. With rounding to the nearest, both 0.0 and 1.0 are possible outcomes. This is functionally equivalent to producing 0.* where * is an infinitely long random bit stream, and then rounding. If * is an infinite stream of zeros, then the number is exactly zero, and if * is an infinite stream of ones, then the number is exactly one.\r\n\r\nFor this to be done correctly, more than one `u32` may need to be generated for a random `f32` if initially we get lots of zeros. But this is improbable so it should not be considered a performance issue. For example for `f32`, if the first generated `u32` does not start with eight zeros, it is sufficient: let's say the generated number is seven zeros followed by 25 ones. Then the output should be `0.0000_000` followed by 25 ones. This would produce an `f32` equal to (2−ɛ)×2<sup>−8</sup>, but 2−ɛ only requires 24 of our ones. The 25th significant bit is used to see if we should round down or up, so if that bit is zero we round down returning (2−ɛ)×2<sup>−8</sup>, otherwise we round up returning 2<sup>−7</sup>. Note that we do not need to care about ties-to-even here, since * is infinitely long a tie has zero probability.\r\n\r\nFor three or more `u32` numbers to be required, the first `u32` has to be exactly zero, and the second `u32` must start with seven zeros. So the probability that one `u32` is required is 1−2<sup>−8</sup>, the probability that two `u32` values are required is 2<sup>−8</sup>−2<sup>−40</sup>, and the probability that three or more are required is 2<sup>−40</sup>."},"comment":{"url":"https://api.github.com/repos/dhardy/rand/issues/comments/380694736","html_url":"https://github.com/dhardy/rand/issues/85#issuecomment-380694736","issue_url":"https://api.github.com/repos/dhardy/rand/issues/85","id":380694736,"user":{"login":"dhardy","id":134893,"avatar_url":"https://avatars1.githubusercontent.com/u/134893?v=4","gravatar_id":"","url":"https://api.github.com/users/dhardy","html_url":"https://github.com/dhardy","followers_url":"https://api.github.com/users/dhardy/followers","following_url":"https://api.github.com/users/dhardy/following{/other_user}","gists_url":"https://api.github.com/users/dhardy/gists{/gist_id}","starred_url":"https://api.github.com/users/dhardy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dhardy/subscriptions","organizations_url":"https://api.github.com/users/dhardy/orgs","repos_url":"https://api.github.com/users/dhardy/repos","events_url":"https://api.github.com/users/dhardy/events{/privacy}","received_events_url":"https://api.github.com/users/dhardy/received_events","type":"User","site_admin":false},"created_at":"2018-04-12T06:36:43Z","updated_at":"2018-04-12T06:36:43Z","author_association":"OWNER","body":"Yes, probably nothing. But lets leave this open at least until we have some high-precision range integrated."}}
{"actor":{"display_login":"dhardy"}}