tpl/collections: Seed random on init only

This commit is contained in:
liguoqinjim 2018-01-28 01:51:12 +08:00 committed by Bjørn Erik Pedersen
parent ed4a00e46f
commit 83c761b71a
1 changed files with 4 additions and 1 deletions

View File

@ -29,6 +29,10 @@ import (
"github.com/spf13/cast"
)
func init() {
rand.Seed(time.Now().UTC().UnixNano())
}
// New returns a new instance of the collections-namespaced template functions.
func New(deps *deps.Deps) *Namespace {
return &Namespace{
@ -474,7 +478,6 @@ func (ns *Namespace) Shuffle(seq interface{}) (interface{}, error) {
shuffled := reflect.MakeSlice(reflect.TypeOf(seq), seqv.Len(), seqv.Len())
rand.Seed(time.Now().UTC().UnixNano())
randomIndices := rand.Perm(seqv.Len())
for index, value := range randomIndices {