Skip to content

Commit

Permalink
fix(tplfunc): deprecated rand seed
Browse files Browse the repository at this point in the history
  • Loading branch information
iyear committed Feb 9, 2024
1 parent 0a04d8f commit 51c17bd
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions pkg/tplfunc/math.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,16 @@ import (

var Math = []Func{Rand()}

var rnd *rand.Rand

func init() {
rand.Seed(time.Now().Unix())
rnd = rand.New(rand.NewSource(time.Now().Unix()))
}

func Rand() Func {
return func(funcMap template.FuncMap) {
funcMap["rand"] = func(min, max int) int {
return rand.Intn(max-min) + min
return rnd.Intn(max-min) + min
}
}
}

0 comments on commit 51c17bd

Please sign in to comment.