mirror of
https://github.com/MontFerret/ferret.git
synced 2025-07-05 00:49:00 +02:00
#496_fix_RandomToken_on_Windows (#497)
This commit is contained in:
@ -17,6 +17,10 @@ const (
|
|||||||
letterIdxMax = 63 / letterIdxBits // # of letter indices fitting in 63 bits
|
letterIdxMax = 63 / letterIdxBits // # of letter indices fitting in 63 bits
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// randSrc is a global variable because of this issue
|
||||||
|
// https://github.com/golang/go/issues/8926
|
||||||
|
var randSrc = rand.NewSource(time.Now().UnixNano())
|
||||||
|
|
||||||
// RandomToken generates a pseudo-random token string with the specified length. The algorithm for token generation should be treated as opaque.
|
// RandomToken generates a pseudo-random token string with the specified length. The algorithm for token generation should be treated as opaque.
|
||||||
// @param length (Int) - The desired string length for the token. It must be greater than 0 and at most 65536.
|
// @param length (Int) - The desired string length for the token. It must be greater than 0 and at most 65536.
|
||||||
// @return (String) - A generated token consisting of lowercase letters, uppercase letters and numbers.
|
// @return (String) - A generated token consisting of lowercase letters, uppercase letters and numbers.
|
||||||
@ -34,8 +38,6 @@ func RandomToken(_ context.Context, args ...core.Value) (core.Value, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
size := args[0].(values.Int)
|
size := args[0].(values.Int)
|
||||||
randSrc := rand.NewSource(time.Now().UnixNano())
|
|
||||||
|
|
||||||
b := make([]byte, size)
|
b := make([]byte, size)
|
||||||
|
|
||||||
for i, cache, remain := size-1, randSrc.Int63(), letterIdxMax; i >= 0; {
|
for i, cache, remain := size-1, randSrc.Int63(), letterIdxMax; i >= 0; {
|
||||||
|
Reference in New Issue
Block a user