mirror of https://github.com/veypi/OneAuth.git
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
34 lines
627 B
Go
34 lines
627 B
Go
|
3 months ago
|
//
|
||
|
|
// utils.go
|
||
|
|
// Copyright (C) 2025 veypi <i@veypi.com>
|
||
|
|
// 2025-07-15 17:13
|
||
|
|
// Distributed under terms of the MIT license.
|
||
|
|
//
|
||
|
|
|
||
|
|
package utils
|
||
|
|
|
||
|
|
import (
|
||
|
|
"math/rand"
|
||
|
|
"time"
|
||
|
|
"unsafe"
|
||
|
|
)
|
||
|
|
|
||
|
|
var letters = []byte("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890")
|
||
|
|
var size = int32(len(letters))
|
||
|
|
var seed = rand.New(rand.NewSource(time.Now().UnixNano()))
|
||
|
|
|
||
|
|
// RandSeq produce random string seq
|
||
|
|
func RandSeq(n int) string {
|
||
|
|
b := make([]byte, n)
|
||
|
|
for i := range b {
|
||
|
|
b[i] = letters[seed.Int31n(size)]
|
||
|
|
}
|
||
|
|
return *(*string)(unsafe.Pointer(&b))
|
||
|
|
}
|
||
|
|
|
||
|
|
func Rand(n int) []byte {
|
||
|
|
b := make([]byte, n)
|
||
|
|
seed.Read(b)
|
||
|
|
return b
|
||
|
|
}
|