tpl/collections: Seed random on init only
authorliguoqinjim <liguoqinjim23@gmail.com>
Sat, 27 Jan 2018 17:51:12 +0000 (01:51 +0800)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Sat, 27 Jan 2018 17:51:12 +0000 (18:51 +0100)
tpl/collections/collections.go

index 34b8e7f77fd64aeb857b3d5c3b4bfcabbac32396..d1b97677fdb900a62adbde0b11b692776d9e3b83 100644 (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 {