EvilZone

Programming and Scripting => Other => : kenjoe41 September 10, 2014, 03:17:20 PM

: [Go] Random password generator
: kenjoe41 September 10, 2014, 03:17:20 PM
This is my version of the random password generator i wrote in C++.
: (go)
package main

import (
"fmt"
"math/rand"
"os"
"strconv"
"time"
)

func main() {
var length int
if len(os.Args) != 2 {
length = 8
} else {
length, _ = strconv.Atoi(os.Args[1])
}
chars := ("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890!@#$%^&*()`~-_=+[{]{\\|;:'\",<.>/? ")

rnd := rand.New(rand.NewSource(time.Now().UTC().UnixNano()))//entropy
lenChars := len(chars)
password := make([]byte, length)
for i := 0; i < length; i++ {
password[i] = chars[rnd.Intn(lenChars)]
}
fmt.Println(string(password))
}