github.com/searKing/golang/go@v1.2.117/crypto/rand/seed_math.go (about)

     1  // Copyright 2020 The searKing Author. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package rand
     6  
     7  import (
     8  	"math/rand"
     9  	"time"
    10  )
    11  
    12  // https://www.calhoun.io/creating-random-strings-in-go/
    13  // we are able to isolate it so that no other code can affect our seed.
    14  // This is important,
    15  // because another piece of code we import might also seed the math/rand package and
    16  // cause all of our “random” functions to not really be that random.
    17  // For example,
    18  // if we seed with rand.Seed(time.Now().UnixNano())
    19  // and then another initializer calls rand.Seed(1) our seed will get overridden,
    20  // and that definitely isn’t what we want.
    21  // By using a rand.Rand instance
    22  // we are able to prevent this from happening to our random number generator.
    23  var seededRandMath = rand.New(rand.NewSource(time.Now().UnixNano()))