mirror of
https://github.com/yudai/gotty.git
synced 2026-01-04 16:48:50 +01:00
Refactor
This commit is contained in:
parent
54403dd678
commit
a6133f34b7
54 changed files with 2140 additions and 1334 deletions
18
pkg/randomstring/generate.go
Normal file
18
pkg/randomstring/generate.go
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
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)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue