-
Notifications
You must be signed in to change notification settings - Fork 18k
math/rand: rand.Float64() twice slower since Dec 18 #7267
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
Labels
Milestone
Comments
Maybe something like this could do the trick // unchanged from 1.2. A direct cast to float32 may give 1.0, but should a cast preserve the [0,1) condition? Something like the line below cold be done. func (r *Rand) Float64() float64 { return float64(r.Int63()) / (1 << 63) } //All random bits preserved and it won't be 1.0. Value 1-1.e-7 may need some tweak func (r *Rand) Float32() float32 { return float32(f64*(1-1.e-7)) } Example code: http://play.golang.org/p/fliCIqAVHT |
Maybe something like this could do the trick // Using Int63. The value 1.-1.e-16 may need some tweak func (r *Rand) Float64() float64 { return float64(r.Int63()) / (1 << 63) * (1.-1.e-16) } // Value 1-1.e-7 may need some tweak func (r *Rand) Float32() float32 { return float32(r.Float64() * (1.-1.e-7))} Example code: http://play.golang.org/p/YeRP-2xEpK |
https://golang.org/cl/69980047 Status changed to Started. |
This issue was closed by revision 1a936eb. Status changed to Fixed. |
This issue was closed.
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
The text was updated successfully, but these errors were encountered: