Skip to content

Commit

Permalink
Merge pull request etcd-io#16447 from gocurr/remove_math_rand_seed
Browse files Browse the repository at this point in the history
all: stop using math/rand.Seed
  • Loading branch information
serathius authored Aug 21, 2023
2 parents 0f48f9b + 52748f6 commit 4e24d4a
Show file tree
Hide file tree
Showing 7 changed files with 0 additions and 14 deletions.
2 changes: 0 additions & 2 deletions pkg/adt/interval_tree_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"math/rand"
"reflect"
"testing"
"time"
)

// TestIntervalTreeInsert tests interval tree insertion.
Expand Down Expand Up @@ -360,7 +359,6 @@ func TestIntervalTreeRandom(t *testing.T) {
ivs := make(map[xy]struct{})
ivt := NewIntervalTree()
maxv := 128
rand.Seed(time.Now().UnixNano())

for i := rand.Intn(maxv) + 1; i != 0; i-- {
x, y := int64(rand.Intn(maxv)), int64(rand.Intn(maxv))
Expand Down
1 change: 0 additions & 1 deletion pkg/proxy/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -806,7 +806,6 @@ func computeLatency(lat, rv time.Duration) time.Duration {
rv = lat / 10
}
now := time.Now()
mrand.Seed(int64(now.Nanosecond()))
sign := 1
if now.Second()%2 == 0 {
sign = -1
Expand Down
1 change: 0 additions & 1 deletion pkg/proxy/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -628,7 +628,6 @@ func testServerHTTP(t *testing.T, secure, delayTx bool) {

func newUnixAddr() string {
now := time.Now().UnixNano()
rand.Seed(now)
addr := fmt.Sprintf("%X%X.unix-conn", now, rand.Intn(35000))
os.RemoveAll(addr)
return addr
Expand Down
2 changes: 0 additions & 2 deletions pkg/stringutil/rand.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ package stringutil

import (
"math/rand"
"time"
)

// UniqueStrings returns a slice of randomly generated unique strings.
Expand Down Expand Up @@ -45,7 +44,6 @@ func RandomStrings(slen uint, n int) (ss []string) {
const chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"

func RandString(l uint) string {
rand.Seed(time.Now().UnixNano())
s := make([]byte, l)
for i := 0; i < int(l); i++ {
s[i] = chars[rand.Intn(len(chars))]
Expand Down
3 changes: 0 additions & 3 deletions server/etcdserver/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"expvar"
"fmt"
"math"
"math/rand"
"net/http"
"path"
"regexp"
Expand Down Expand Up @@ -120,8 +119,6 @@ var (
)

func init() {
rand.Seed(time.Now().UnixNano())

expvar.Publish(
"file_descriptor_limit",
expvar.Func(
Expand Down
4 changes: 0 additions & 4 deletions server/lease/lessor_bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,6 @@ func BenchmarkLessorRenew100000(b *testing.B) { benchmarkLessorRenew(100000, b)
func BenchmarkLessorFindExpired10000(b *testing.B) { benchmarkLessorFindExpired(10000, b) }
func BenchmarkLessorFindExpired100000(b *testing.B) { benchmarkLessorFindExpired(100000, b) }

func init() {
rand.Seed(time.Now().UTC().UnixNano())
}

const (
// minTTL keep lease will not auto expire in benchmark
minTTL = 1000
Expand Down
1 change: 0 additions & 1 deletion tests/integration/clientv3/snapshot/v3_snapshot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ func createSnapshotFile(t *testing.T, cfg *embed.Config, kvs []kv) (version stri
func newEmbedURLs(n int) (urls []url.URL) {
urls = make([]url.URL, n)
for i := 0; i < n; i++ {
rand.Seed(int64(time.Now().Nanosecond()))
u, _ := url.Parse(fmt.Sprintf("unix://localhost:%d", rand.Intn(45000)))
urls[i] = *u
}
Expand Down

0 comments on commit 4e24d4a

Please sign in to comment.