mirror of
https://github.com/pion/webrtc.git
synced 2025-10-26 08:40:38 +08:00
Fix randoms
Use seeded mathematical random where uniqueness is needed but not required to be cryptographic.
This commit is contained in:
@@ -2,16 +2,17 @@ package signal
|
||||
|
||||
import (
|
||||
"math/rand"
|
||||
"time"
|
||||
)
|
||||
|
||||
// RandSeq generates a random string to serve as dummy data
|
||||
//
|
||||
// It returns a deterministic sequence of values each time a program is run.
|
||||
// Use rand.Seed() function in your real applications.
|
||||
func RandSeq(n int) string {
|
||||
r := rand.New(rand.NewSource(time.Now().UnixNano()))
|
||||
letters := []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
|
||||
b := make([]rune, n)
|
||||
for i := range b {
|
||||
b[i] = letters[r.Intn(len(letters))]
|
||||
b[i] = letters[rand.Intn(len(letters))]
|
||||
}
|
||||
return string(b)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user