Closed
Description
https://golang.org/cl/22730043 fixed a bug in Float32/Float64 to make sure they never return 1.0. https://golang.org/cl/69980047 sped up Int31n and Int64n (and therefore Intn, Float32, and Float64) for powers of two. The changes have the effect that calling rand with a specific seed and then calling any of these methods can produce a different number sequence in Go 1.3 than it did in earlier versions of Go. The Float32/Float64 change is fixing incorrect code, so we have to keep it. The Int31n/Int64n change is just a performance improvement (but it affects Intn, Float32, and Float64 output too). It's unclear whether we should be trying to keep the output for a fixed seed fixed over different releases. If so, we should roll back the performance change and probably make the Float32/Float64 bug fix differently: look for 1.0 and throw it away. If not, we need to call this out in the release notes. I am leaning toward rolling things back but I'm still on the fence. changeset: 18661:3ed9d5c72102 user: Jeff R. Allen <jra@nella.org> date: Wed Dec 18 15:38:53 2013 -0500 files: src/pkg/math/rand/example_test.go src/pkg/math/rand/rand.go src/pkg/math/rand/rand_test.go description: math/rand: Float32/64 must only return values in [0,1) Float32 and Float64 are now both created by taking the ratio of two integers which are chosen to fit entirely into the precision of the desired float type. The previous code could cast a Float64 with more than 23 bits of ".99999" into a Float32 of 1.0, which is not in [0,1). Float32 went from 15 to 21 ns/op (but is now correct). Fixes issue #6721. R=golang-dev, iant, rsc CC=golang-dev https://golang.org/cl/22730043 Committer: Russ Cox <rsc@golang.org> changeset: 19327:361aac3d88a0 user: Russ Cox <rsc@golang.org> date: Mon Mar 03 20:43:23 2014 -0500 files: src/pkg/math/rand/rand.go src/pkg/math/rand/rand_test.go description: math/rand: speed up Float32, Float64 Actually, speed up Int31n and Int63n by avoiding retry loop. benchmark old ns/op new ns/op delta BenchmarkFloat32 32 26 -19.45% BenchmarkFloat64 46 23 -49.47% Fixes issue #7267. LGTM=bradfitz R=golang-codereviews, bradfitz CC=golang-codereviews https://golang.org/cl/69980047