Skip to content

Commit

Permalink
math/rand/v2: remove Rand.Seed
Browse files Browse the repository at this point in the history
Removing Rand.Seed lets us remove lockedSource as well,
along with the ambiguity in globalRand about which source
to use.

For #61716.

Change-Id: Ibe150520dd1e7dd87165eacaebe9f0c2daeaedfd
Reviewed-on: https://go-review.googlesource.com/c/go/+/502498
Reviewed-by: Dmitri Shuralyov <[email protected]>
Reviewed-by: Rob Pike <[email protected]>
LUCI-TryBot-Result: Go LUCI <[email protected]>
Auto-Submit: Russ Cox <[email protected]>
  • Loading branch information
rsc authored and gopherbot committed Oct 30, 2023
1 parent 48bd1fc commit 1cc5b34
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 315 deletions.
9 changes: 2 additions & 7 deletions api/next/61716.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ pkg math/rand/v2, func NewSource(int64) Source #61716
pkg math/rand/v2, func NewZipf(*Rand, float64, float64, uint64) *Zipf #61716
pkg math/rand/v2, func NormFloat64() float64 #61716
pkg math/rand/v2, func Perm(int) []int #61716
pkg math/rand/v2, func Seed //deprecated #61716
pkg math/rand/v2, func Seed(int64) #61716
pkg math/rand/v2, func Shuffle(int, func(int, int)) #61716
pkg math/rand/v2, func Uint32() uint32 #61716
pkg math/rand/v2, func Uint64() uint64 #61716
Expand All @@ -28,17 +26,14 @@ pkg math/rand/v2, method (*Rand) Int64N(int64) int64 #61716
pkg math/rand/v2, method (*Rand) IntN(int) int #61716
pkg math/rand/v2, method (*Rand) NormFloat64() float64 #61716
pkg math/rand/v2, method (*Rand) Perm(int) []int #61716
pkg math/rand/v2, method (*Rand) Seed(int64) #61716
pkg math/rand/v2, method (*Rand) Shuffle(int, func(int, int)) #61716
pkg math/rand/v2, method (*Rand) Uint32() uint32 #61716
pkg math/rand/v2, method (*Rand) Uint64() uint64 #61716
pkg math/rand/v2, method (*Zipf) Uint64() uint64 #61716
pkg math/rand/v2, type Rand struct #61716
pkg math/rand/v2, type Source interface { Int64, Seed } #61716
pkg math/rand/v2, type Source interface { Int64 } #61716
pkg math/rand/v2, type Source interface, Int64() int64 #61716
pkg math/rand/v2, type Source interface, Seed(int64) #61716
pkg math/rand/v2, type Source64 interface { Int64, Seed, Uint64 } #61716
pkg math/rand/v2, type Source64 interface { Int64, Uint64 } #61716
pkg math/rand/v2, type Source64 interface, Int64() int64 #61716
pkg math/rand/v2, type Source64 interface, Seed(int64) #61716
pkg math/rand/v2, type Source64 interface, Uint64() uint64 #61716
pkg math/rand/v2, type Zipf struct #61716
8 changes: 4 additions & 4 deletions src/math/rand/v2/auto_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,20 @@ import (
func TestAuto(t *testing.T) {
// Pull out 10 int64s from the global source
// and then check that they don't appear in that
// order in the deterministic Seed(1) result.
// order in the deterministic seeded result.
var out []int64
for i := 0; i < 10; i++ {
out = append(out, Int64())
}

// Look for out in Seed(1)'s output.
// Look for out in seeded output.
// Strictly speaking, we should look for them in order,
// but this is good enough and not significantly more
// likely to have a false positive.
Seed(1)
r := New(NewSource(1))
found := 0
for i := 0; i < 1000; i++ {
x := Int64()
x := r.Int64()
if x == out[found] {
found++
if found == len(out) {
Expand Down
148 changes: 0 additions & 148 deletions src/math/rand/v2/default_test.go

This file was deleted.

8 changes: 2 additions & 6 deletions src/math/rand/v2/race_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,8 @@ func TestConcurrent(t *testing.T) {
for i := 0; i < numRoutines; i++ {
go func(i int) {
defer wg.Done()
buf := make([]byte, 997)
var seed int64
for j := 0; j < numCycles; j++ {
var seed int64
seed += int64(ExpFloat64())
seed += int64(Float32())
seed += int64(Float64())
Expand All @@ -38,11 +37,8 @@ func TestConcurrent(t *testing.T) {
for _, p := range Perm(10) {
seed += int64(p)
}
for _, b := range buf {
seed += int64(b)
}
Seed(int64(i*j) * seed)
}
_ = seed
}(i)
}
}
Loading

0 comments on commit 1cc5b34

Please sign in to comment.