shithub: hugo

Download patch

ref: 83c761b71a980aee6331179b271c7e24e999e8eb
parent: ed4a00e46f2344320a22f07febe5aec4075cb3fb
author: liguoqinjim <[email protected]>
date: Sat Jan 27 20:51:12 EST 2018

tpl/collections: Seed random on init only


--- a/tpl/collections/collections.go
+++ b/tpl/collections/collections.go
@@ -29,6 +29,10 @@
 	"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 @@
 
 	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 {