Skip to content

Commit

Permalink
tpl/collections: Seed random on init only
Browse files Browse the repository at this point in the history
  • Loading branch information
liguoqinjim authored and bep committed Jan 27, 2018
1 parent ed4a00e commit 83c761b
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion tpl/collections/collections.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 83c761b

Please sign in to comment.