Adding upstream version 0.0~git20250307.c2e6a77.
Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
parent
be99035e76
commit
b6e042e2af
64 changed files with 10976 additions and 0 deletions
31
random.go
Normal file
31
random.go
Normal file
|
@ -0,0 +1,31 @@
|
|||
package tygoja
|
||||
|
||||
import (
|
||||
mathRand "math/rand"
|
||||
"time"
|
||||
)
|
||||
|
||||
const defaultRandomAlphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
|
||||
|
||||
func init() {
|
||||
mathRand.Seed(time.Now().UnixNano())
|
||||
}
|
||||
|
||||
// PseudorandomString generates a pseudorandom string from the default
|
||||
// alphabet with the specified length.
|
||||
func PseudorandomString(length int) string {
|
||||
return PseudorandomStringWithAlphabet(length, defaultRandomAlphabet)
|
||||
}
|
||||
|
||||
// PseudorandomStringWithAlphabet generates a pseudorandom string
|
||||
// with the specified length and characters set.
|
||||
func PseudorandomStringWithAlphabet(length int, alphabet string) string {
|
||||
b := make([]byte, length)
|
||||
max := len(alphabet)
|
||||
|
||||
for i := range b {
|
||||
b[i] = alphabet[mathRand.Intn(max)]
|
||||
}
|
||||
|
||||
return string(b)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue