mirror of
https://github.com/AlexxIT/go2rtc.git
synced 2025-10-06 16:57:29 +08:00
20 lines
353 B
Go
20 lines
353 B
Go
package core
|
|
|
|
import (
|
|
cryptorand "crypto/rand"
|
|
)
|
|
|
|
const digits = "0123456789abcdefghijklmnopqrstuvwxyz"
|
|
const maxSize = byte(len(digits))
|
|
|
|
func RandString(size byte) string {
|
|
b := make([]byte, size)
|
|
if _, err := cryptorand.Read(b); err != nil {
|
|
panic(err)
|
|
}
|
|
for i := byte(0); i < size; i++ {
|
|
b[i] = digits[b[i]%maxSize]
|
|
}
|
|
return string(b)
|
|
}
|