Minor changes

This commit is contained in:
Winni Neessen 2021-03-20 22:18:16 +01:00
parent 808725501d
commit 19ed4da161
Signed by: wneessen
GPG key ID: 385AC9889632126E

6
apg.go
View file

@ -4,7 +4,6 @@ import (
"crypto/rand" "crypto/rand"
"flag" "flag"
"fmt" "fmt"
"log"
"math/big" "math/big"
"os" "os"
"regexp" "regexp"
@ -119,7 +118,7 @@ func main() {
func getRandChar(charRange *string, pwLength int) string { func getRandChar(charRange *string, pwLength int) string {
availCharsLength := len(*charRange) availCharsLength := len(*charRange)
charSlice := []byte(*charRange) charSlice := []byte(*charRange)
returnString := []byte{} returnString := make([]byte, pwLength)
for i := 0; i < pwLength; i++ { for i := 0; i < pwLength; i++ {
randNum := getRandNum(availCharsLength) randNum := getRandNum(availCharsLength)
returnString = append(returnString, charSlice[randNum]) returnString = append(returnString, charSlice[randNum])
@ -131,7 +130,8 @@ func getRandNum(maxNum int) int {
maxNumBigInt := big.NewInt(int64(maxNum)) maxNumBigInt := big.NewInt(int64(maxNum))
randNum64, err := rand.Int(rand.Reader, maxNumBigInt) randNum64, err := rand.Int(rand.Reader, maxNumBigInt)
if err != nil { if err != nil {
log.Fatalf("An error occured generating random number: %v", err) fmt.Printf("An error occured while generating random number: %v", err)
os.Exit(1)
} }
randNum := int(randNum64.Int64()) randNum := int(randNum64.Int64())
return randNum return randNum