]> Cypherpunks.ru repositories - gostls13.git/commitdiff
all: remove uses of rand.Seed
authorRuss Cox <rsc@golang.org>
Tue, 25 Oct 2022 16:53:30 +0000 (12:53 -0400)
committerGopher Robot <gobot@golang.org>
Wed, 26 Oct 2022 16:24:57 +0000 (16:24 +0000)
As of CL 443058, rand.Seed is not necessary to call,
nor is it a particular good idea.

For #54880.

Change-Id: If9d70763622c09008599db8c97a90fcbe285c6f8
Reviewed-on: https://go-review.googlesource.com/c/go/+/445395
Run-TryBot: Russ Cox <rsc@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Auto-Submit: Russ Cox <rsc@golang.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
src/cmd/compile/internal/ssagen/pgen.go
src/crypto/rand/rand_batched_test.go
src/math/rand/example_test.go
src/strconv/atof_test.go

index 9aaf4b81e0e60a504f49dc749da69daeb3132d3b..7e7c13adc97eb00de9f9548e1029ea7ff22ad2a5 100644 (file)
@@ -6,11 +6,8 @@ package ssagen
 
 import (
        "internal/buildcfg"
-       "internal/race"
-       "math/rand"
        "sort"
        "sync"
-       "time"
 
        "cmd/compile/internal/base"
        "cmd/compile/internal/ir"
@@ -214,12 +211,6 @@ func Compile(fn *ir.Func, worker int) {
        fieldtrack(pp.Text.From.Sym, fn.FieldTrack)
 }
 
-func init() {
-       if race.Enabled {
-               rand.Seed(time.Now().UnixNano())
-       }
-}
-
 // StackOffset returns the stack location of a LocalSlot relative to the
 // stack pointer, suitable for use in a DWARF location entry. This has nothing
 // to do with its offset in the user variable.
index 89953776a89ac69e718b0b62c79b6a58d98af1cf..02f48931e365ff5d280bce5c087e007b27be4bcc 100644 (file)
@@ -8,7 +8,6 @@ package rand
 
 import (
        "bytes"
-       "encoding/binary"
        "errors"
        prand "math/rand"
        "testing"
@@ -33,10 +32,6 @@ func TestBatched(t *testing.T) {
 }
 
 func TestBatchedBuffering(t *testing.T) {
-       var prandSeed [8]byte
-       Read(prandSeed[:])
-       prand.Seed(int64(binary.LittleEndian.Uint64(prandSeed[:])))
-
        backingStore := make([]byte, 1<<23)
        prand.Read(backingStore)
        backingMarker := backingStore[:]
index f691e39d648fd2986181c127c5a5e3e2f5010078..d656f470ebbfd66f5f7a9c1f5bd91510112f2b91 100644 (file)
@@ -16,10 +16,6 @@ import (
 // the output of the random number generator when given a fixed seed.
 
 func Example() {
-       // Seeding with the same value results in the same random sequence each run.
-       // For different numbers, seed with a different value, such as
-       // time.Now().UnixNano(), which yields a constantly-changing number.
-       rand.Seed(42)
        answers := []string{
                "It is certain",
                "It is decidedly so",
@@ -43,7 +39,6 @@ func Example() {
                "Very doubtful",
        }
        fmt.Println("Magic 8-Ball says:", answers[rand.Intn(len(answers))])
-       // Output: Magic 8-Ball says: As I see it yes
 }
 
 // This example shows the use of each of the methods on a *Rand.
@@ -116,9 +111,6 @@ func ExampleShuffle() {
                words[i], words[j] = words[j], words[i]
        })
        fmt.Println(words)
-
-       // Output:
-       // [mouth my the of runs corners from ink]
 }
 
 func ExampleShuffle_slicesInUnison() {
@@ -132,26 +124,10 @@ func ExampleShuffle_slicesInUnison() {
        for i := range numbers {
                fmt.Printf("%c: %c\n", letters[i], numbers[i])
        }
-
-       // Output:
-       // C: 3
-       // D: 4
-       // A: 1
-       // E: 5
-       // B: 2
 }
 
 func ExampleIntn() {
-       // Seeding with the same value results in the same random sequence each run.
-       // For different numbers, seed with a different value, such as
-       // time.Now().UnixNano(), which yields a constantly-changing number.
-       rand.Seed(86)
        fmt.Println(rand.Intn(100))
        fmt.Println(rand.Intn(100))
        fmt.Println(rand.Intn(100))
-
-       // Output:
-       // 42
-       // 76
-       // 30
 }
index aa587a473cdde8deff38643cf44983d773c9afc2..7b287b421945ca2212479ca51e58356291e9202d 100644 (file)
@@ -12,7 +12,6 @@ import (
        "strings"
        "sync"
        "testing"
-       "time"
 )
 
 type atofTest struct {
@@ -463,7 +462,6 @@ func initAtofOnce() {
        }
 
        // Generate random inputs for tests and benchmarks
-       rand.Seed(time.Now().UnixNano())
        if testing.Short() {
                atofRandomTests = make([]atofSimpleTest, 100)
        } else {