Skip to content

Commit

Permalink
Updates math rand to v2 (#3109)
Browse files Browse the repository at this point in the history
  • Loading branch information
alishakawaguchi authored Jan 9, 2025
1 parent 4f3914f commit 7cc857a
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions worker/pkg/rng/rng.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package rng

import (
"math/rand"
"math/rand/v2"
"sync"
)

Expand All @@ -21,20 +21,20 @@ type Randomizer struct {
}

func New(seed int64) *Randomizer {
rng := rand.New(rand.NewSource(seed)) //nolint:gosec
rng := rand.New(rand.NewPCG(uint64(seed), uint64(seed))) //nolint:gosec
return &Randomizer{rng: rng}
}

func (r *Randomizer) Int63n(n int64) int64 {
r.mu.Lock()
defer r.mu.Unlock()
return r.rng.Int63n(n)
return r.rng.Int64N(n)
}

func (r *Randomizer) Intn(n int) int {
r.mu.Lock()
defer r.mu.Unlock()
return r.rng.Intn(n)
return r.rng.IntN(n)
}

func (r *Randomizer) Float64() float64 {
Expand All @@ -46,7 +46,7 @@ func (r *Randomizer) Float64() float64 {
func (r *Randomizer) Int63() int64 {
r.mu.Lock()
defer r.mu.Unlock()
return r.rng.Int63()
return r.rng.Int64()
}

func (r *Randomizer) Int() int {
Expand Down

0 comments on commit 7cc857a

Please sign in to comment.