hugo

Unnamed repository; edit this file 'description' to name the repository.

git clone git://git.shimmy1996.com/hugo.git
commit 83c761b71a980aee6331179b271c7e24e999e8eb
parent ed4a00e46f2344320a22f07febe5aec4075cb3fb
Author: liguoqinjim <liguoqinjim23@gmail.com>
Date:   Sun, 28 Jan 2018 01:51:12 +0800

tpl/collections: Seed random on init only


Diffstat:
Mtpl/collections/collections.go | 5++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git 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 {