From 83c761b71a980aee6331179b271c7e24e999e8eb Mon Sep 17 00:00:00 2001 From: liguoqinjim Date: Sun, 28 Jan 2018 01:51:12 +0800 Subject: [PATCH] tpl/collections: Seed random on init only --- tpl/collections/collections.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tpl/collections/collections.go b/tpl/collections/collections.go index 34b8e7f77fd..d1b97677fdb 100644 --- a/tpl/collections/collections.go +++ b/tpl/collections/collections.go @@ -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 {