Make rand.Seed not deprecated

This commit is contained in:
Sergey Stepanov 2023-02-17 18:12:38 +03:00
parent c237ee1a47
commit faf347a44a
No known key found for this signature in database
GPG key ID: A56B4929BAA8556B
6 changed files with 15 additions and 7 deletions

View file

@ -13,7 +13,7 @@ import (
var Version = "?"
func main() {
rand.Seed(time.Now().UTC().UnixNano())
rand.New(rand.NewSource(time.Now().UnixNano())) // !to remove when bumped to 1.20
conf := config.NewConfig()
conf.ParseFlags()

View file

@ -14,7 +14,7 @@ import (
var Version = "?"
func run() {
rand.Seed(time.Now().UTC().UnixNano())
rand.New(rand.NewSource(time.Now().UnixNano())) // !to remove when bumped to 1.20
conf := config.NewConfig()
conf.ParseFlags()

View file

@ -1,6 +1,7 @@
package zip
import (
cr "crypto/rand"
"fmt"
"math/rand"
"reflect"
@ -62,10 +63,15 @@ func BenchmarkCompressions(b *testing.B) {
{name: "compress", size: 1024 * 1024 * 2},
}
for _, bm := range benchmarks {
rand.Seed(time.Now().UnixNano())
rand.New(rand.NewSource(time.Now().UnixNano())) // !to remove when bumped to 1.20
b.Run(fmt.Sprintf("%v %v", bm.name, bm.size), func(b *testing.B) {
b.StopTimer()
dat := make([]byte, bm.size)
rand.Read(dat)
_, err := cr.Read(dat)
if err != nil {
b.Fatal(err)
}
b.StartTimer()
for i := 0; i < b.N; i++ {
_, _ = Compress(dat, "test")
}

View file

@ -167,7 +167,7 @@ func TestStateConcurrency(t *testing.T) {
})
mock.handleAudio(func(_ *emulator.GameAudio) {})
rand.Seed(int64(test.seed))
rand.New(rand.NewSource(int64(test.seed))) // !to remove when bumped to 1.20
t.Logf("Random seed is [%v]\n", test.seed)
t.Logf("Save path is [%v]\n", mock.paths.save)

View file

@ -138,7 +138,7 @@ func BenchmarkResampler(b *testing.B) {
}
func gen(l int) []int16 {
rand.Seed(time.Now().Unix())
rand.New(rand.NewSource(time.Now().UnixNano())) // !to remove when bumped to 1.20
nums := make([]int16, l)
for i := range nums {

View file

@ -65,7 +65,9 @@ type (
}
)
func init() { rand.Seed(time.Now().UnixNano()) }
func init() {
rand.New(rand.NewSource(time.Now().UnixNano())) // !to remove when bumped to 1.20
}
// NewRecording creates new media recorder for the emulator.
func NewRecording(meta Meta, log *logger.Logger, opts Options) *Recording {