Skip to content

Commit

Permalink
refactor(rand): enhance random number generation security
Browse files Browse the repository at this point in the history
- Replace `math/rand` with `crypto/rand` and alias `math/rand` as `mathrand`
- Change the random source initialization to use the `mathrand` alias

Signed-off-by: appleboy <[email protected]>
  • Loading branch information
appleboy committed Oct 25, 2024
1 parent a4c6f80 commit b7159ec
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions random/random.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package random

import (
"math/rand"
"crypto/rand"
mathrand "math/rand"
"time"
"unsafe"
)
Expand Down Expand Up @@ -52,7 +53,7 @@ const (
letterIdxMax = 63 / letterIdxBits // # of letter indices fitting in 63 bits
)

var src = rand.NewSource(time.Now().UnixNano())
var src = mathrand.NewSource(time.Now().UnixNano())

func randStringBytesMaskImprSrcUnsafe(n int) string {
b := make([]byte, n)
Expand Down

0 comments on commit b7159ec

Please sign in to comment.