Skip to content

Commit

Permalink
Add MustRandom to base62, which makes it easier to use in tests. (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
jefferai committed Oct 21, 2021
1 parent f7bda98 commit f277d31
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions base62/base62.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,17 @@ const (
csLen = byte(len(charset))
)

// MustRandom generates a random string using base-62 characters. Resulting
// entropy is ~5.95 bits/character. If an error is encountered, MustRandom
// panics.
func MustRandom(length int) string {
out, err := RandomWithReader(length, rand.Reader)
if err != nil {
panic(err)
}
return out
}

// Random generates a random string using base-62 characters.
// Resulting entropy is ~5.95 bits/character.
func Random(length int) (string, error) {
Expand Down

0 comments on commit f277d31

Please sign in to comment.