v8.run/go/exp@v0.0.26-0.20230226010534-afcdbd3f782d/fastrand/float.go (about) 1 package fastrand 2 3 // Float64 returns a random float64 in [0, 1). 4 func (rng *RNG) Float64() float64 { 5 retry: 6 f := float64(rng.Int63()) / (1 << 63) 7 if f == 1 { 8 goto retry 9 } 10 return f 11 } 12 13 // Float32 returns a random float32 in [0, 1). 14 func (rng *RNG) Float32() float32 { 15 retry: 16 f := float32(rng.Float64()) 17 if f == 1 { 18 goto retry 19 } 20 return f 21 } 22 23 func Float64() float64 { 24 r := AcquireRNG() 25 v := r.Float64() 26 ReleaseRNG(r) 27 return v 28 } 29 30 func Float32() float32 { 31 r := AcquireRNG() 32 v := r.Float32() 33 ReleaseRNG(r) 34 return v 35 }