-
Notifications
You must be signed in to change notification settings - Fork 23
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
Conversion to Float #8
Comments
I had believed what I learned in art4711/random-double#2 could be the best approach to convert So I'd like to use the first (simplest and very fast) approach currently. |
An alternative is
This has very small bias: there is a 1/4000 chance that the least significant bit is correlated with the exponent (similar for next bits), and there is a cutoff that lumps all numbers smaller than Note that a correct PRNG with Float64 output should be able to generate Much more important is the conversion to Float32:
A correct RNG would output |
@chethega I think your |
The "obvious" approach of converting to a float, then multiplying by a scale factor is slow, and has the potential to give an answer of
1.0
.The easiest option is:
unfortunately this has the downside that the last bit will always be zero, so you only get 52 bits of randomness per float: see JuliaLang/julia#16344.
A slightly more advanced option (based on this proposal) is:
This gets us 53 bits, but introduces a branch. There might be some clever stuff we can do here though.
The text was updated successfully, but these errors were encountered: