Skip to content

Commit

Permalink
math/rand -> crypto/rand
Browse files Browse the repository at this point in the history
  • Loading branch information
aviau committed Dec 17, 2017
1 parent fe47e21 commit c0536fb
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions cmd/gopass/internal/pwgen/pwgen.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
package pwgen

import (
"math/rand"
"time"
"crypto/rand"
"math/big"
)

//Alpha is a-Z and A-Z
Expand All @@ -33,10 +33,13 @@ var Symbols = []rune("!#$%&'()*+,-./:;<=>?@[]^_`{|}~")

//RandSeq returns a random sequence of lenght n
func RandSeq(n int, runes []rune) string {
rand.Seed(time.Now().UTC().UnixNano())
b := make([]rune, n)
for i := range b {
b[i] = runes[rand.Intn(len(runes))]
randomInt, err := rand.Int(rand.Reader, big.NewInt(int64(len(runes))))
if err != nil {
panic(err)
}
b[i] = runes[randomInt.Int64()]
}
return string(b)
}

0 comments on commit c0536fb

Please sign in to comment.