mirror of
https://github.com/sorenisanerd/gotty.git
synced 2024-11-14 17:34:26 +00:00
19 lines
308 B
Go
19 lines
308 B
Go
|
package randomstring
|
||
|
|
||
|
import (
|
||
|
"crypto/rand"
|
||
|
"math/big"
|
||
|
"strconv"
|
||
|
)
|
||
|
|
||
|
func Generate(length int) string {
|
||
|
const base = 36
|
||
|
size := big.NewInt(base)
|
||
|
n := make([]byte, length)
|
||
|
for i, _ := range n {
|
||
|
c, _ := rand.Int(rand.Reader, size)
|
||
|
n[i] = strconv.FormatInt(c.Int64(), base)[0]
|
||
|
}
|
||
|
return string(n)
|
||
|
}
|