diff options
Diffstat (limited to 'src/math')
| -rw-r--r-- | src/math/rand/rand.go | 30 | ||||
| -rw-r--r-- | src/math/rand/v2/rand.go | 18 |
2 files changed, 22 insertions, 26 deletions
diff --git a/src/math/rand/rand.go b/src/math/rand/rand.go index 78e176e78f..a8ed9c0cb7 100644 --- a/src/math/rand/rand.go +++ b/src/math/rand/rand.go @@ -273,7 +273,7 @@ func (r *Rand) Read(p []byte) (n int, err error) { switch src := r.src.(type) { case *lockedSource: return src.read(p, &r.readVal, &r.readPos) - case *fastSource: + case *runtimeSource: return src.read(p, &r.readVal, &r.readPos) } return read(p, r.src, &r.readVal, &r.readPos) @@ -328,8 +328,8 @@ func globalRand() *Rand { r.Seed(1) } else { r = &Rand{ - src: &fastSource{}, - s64: &fastSource{}, + src: &runtimeSource{}, + s64: &runtimeSource{}, } } @@ -346,29 +346,29 @@ func globalRand() *Rand { return r } -//go:linkname fastrand64 -func fastrand64() uint64 +//go:linkname runtime_rand runtime.rand +func runtime_rand() uint64 -// fastSource is an implementation of Source64 that uses the runtime +// runtimeSource is an implementation of Source64 that uses the runtime // fastrand functions. -type fastSource struct { +type runtimeSource struct { // The mutex is used to avoid race conditions in Read. mu sync.Mutex } -func (*fastSource) Int63() int64 { - return int64(fastrand64() & rngMask) +func (*runtimeSource) Int63() int64 { + return int64(runtime_rand() & rngMask) } -func (*fastSource) Seed(int64) { - panic("internal error: call to fastSource.Seed") +func (*runtimeSource) Seed(int64) { + panic("internal error: call to runtimeSource.Seed") } -func (*fastSource) Uint64() uint64 { - return fastrand64() +func (*runtimeSource) Uint64() uint64 { + return runtime_rand() } -func (fs *fastSource) read(p []byte, readVal *int64, readPos *int8) (n int, err error) { +func (fs *runtimeSource) read(p []byte, readVal *int64, readPos *int8) (n int, err error) { fs.mu.Lock() n, err = read(p, fs, readVal, readPos) fs.mu.Unlock() @@ -405,7 +405,7 @@ func Seed(seed int64) { // Otherwise either // 1) orig == nil, which is the normal case when Seed is the first // top-level function to be called, or - // 2) orig is already a fastSource, in which case we need to change + // 2) orig is already a runtimeSource, in which case we need to change // to a lockedSource. // Either way we do the same thing. diff --git a/src/math/rand/v2/rand.go b/src/math/rand/v2/rand.go index 5382f809e0..f490408472 100644 --- a/src/math/rand/v2/rand.go +++ b/src/math/rand/v2/rand.go @@ -250,20 +250,16 @@ func (r *Rand) Shuffle(n int, swap func(i, j int)) { // globalRand is the source of random numbers for the top-level // convenience functions. -var globalRand = &Rand{src: &fastSource{}} +var globalRand = &Rand{src: &runtimeSource{}} -//go:linkname fastrand64 -func fastrand64() uint64 +//go:linkname runtime_rand runtime.rand +func runtime_rand() uint64 -// fastSource is a Source that uses the runtime fastrand functions. -type fastSource struct{} +// runtimeSource is a Source that uses the runtime fastrand functions. +type runtimeSource struct{} -func (*fastSource) Int64() int64 { - return int64(fastrand64() << 1 >> 1) -} - -func (*fastSource) Uint64() uint64 { - return fastrand64() +func (*runtimeSource) Uint64() uint64 { + return runtime_rand() } // Int64 returns a non-negative pseudo-random 63-bit integer as an int64 |
