Skip to content

Commit

Permalink
Merge pull request #1 from mrnugget/patch-1
Browse files Browse the repository at this point in the history
Cache modulo operator in New
  • Loading branch information
chr4 committed Aug 6, 2014
2 parents 5b429c8 + d0f5a8f commit 4bd7451
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion pwgen.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ const chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_-?
// New() generates a random string of the given length
func New(length int) string {
var bytes = make([]byte, length)
var op = byte(len(chars))

rand.Read(bytes)
for i, b := range bytes {
bytes[i] = chars[b%byte(len(chars))]
bytes[i] = chars[b%op]
}
return string(bytes)
}

0 comments on commit 4bd7451

Please sign in to comment.