mirror of https://github.com/golang/go.git
net: use fastrand64 in randInt
Change-Id: If3d8391d81e8de869dbb3c857f0570817e8aa440 Reviewed-on: https://go-review.googlesource.com/c/go/+/400914 Reviewed-by: Keith Randall <khr@golang.org> Reviewed-by: Keith Randall <khr@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Run-TryBot: Wayne Zuo <wdvxdr@golangcn.org> TryBot-Result: Gopher Robot <gobot@golang.org>
This commit is contained in:
parent
01b8f5e882
commit
a4bbcd4b1f
|
|
@ -13,13 +13,10 @@ import (
|
|||
)
|
||||
|
||||
// provided by runtime
|
||||
func fastrand() uint32
|
||||
func fastrandu() uint
|
||||
|
||||
func randInt() int {
|
||||
x, y := fastrand(), fastrand() // 32-bit halves
|
||||
u := uint(x)<<31 ^ uint(int32(y)) // full uint, even on 64-bit systems; avoid 32-bit shift on 32-bit systems
|
||||
i := int(u >> 1) // clear sign bit, even on 32-bit systems
|
||||
return i
|
||||
return int(fastrandu() >> 1) // clear sign bit
|
||||
}
|
||||
|
||||
func randIntn(n int) int {
|
||||
|
|
|
|||
|
|
@ -199,8 +199,8 @@ func fastrandu() uint {
|
|||
//go:linkname sync_fastrandn sync.fastrandn
|
||||
func sync_fastrandn(n uint32) uint32 { return fastrandn(n) }
|
||||
|
||||
//go:linkname net_fastrand net.fastrand
|
||||
func net_fastrand() uint32 { return fastrand() }
|
||||
//go:linkname net_fastrandu net.fastrandu
|
||||
func net_fastrandu() uint { return fastrandu() }
|
||||
|
||||
//go:linkname os_fastrand os.fastrand
|
||||
func os_fastrand() uint32 { return fastrand() }
|
||||
|
|
|
|||
Loading…
Reference in New Issue