Browse Source

More flexible letter/symbol/nunmber combinations.

master
Greg 2 years ago
parent
commit
a81bebfaf8
  1. 20
      main.go

20
main.go

@ -6,10 +6,16 @@ import (
"math/big"
)
type Generator func() (byte,error)
var chars []byte = []byte("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789~`!@#$%^&*()_+-=[]{}\\|;:'\",./<>?")
var letters []byte = chars[0:52]
var digits []byte = chars[52:62]
var letdig []byte = chars[0:62]
var symbols []byte = chars[62:94]
var digsym []byte = chars[52:94]
var letsym []byte = []byte("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ~`!@#$%^&*()_+-=[]{}\\|;:'\",./<>?")
func gen(s []byte) (byte,error) {
nBig, err := crand.Int(crand.Reader, big.NewInt(int64(len(s))))
@ -32,11 +38,23 @@ func Symbol() (byte,error) {
return gen(symbols)
}
func LetterDigits() (byte,error) {
return gen(letdig)
}
func DigitsSymbols() (byte,error) {
return gen(digsym)
}
func LettersSymbols() (byte, error) {
return gen(letsym)
}
func Char() (byte,error) {
return gen(chars)
}
func Slice(f func() (byte,error), n int) ([]byte,error) {
func Slice(f Generator, n int) ([]byte,error) {
ret := make([]byte,0)
for i := 0; i < n; i++ {
x,err := f()

Loading…
Cancel
Save