Merge 28e216136a into 7dd3037eec
This commit is contained in:
commit
177500d85b
2 changed files with 6 additions and 1 deletions
|
|
@ -56,7 +56,7 @@ func NewLenChars(length int, chars []byte) string {
|
|||
panic("error reading from random source: " + err.Error())
|
||||
}
|
||||
for _, c := range r {
|
||||
if c > maxrb {
|
||||
if maxrb > 0 && c > maxrb {
|
||||
// Skip this number to avoid modulo bias.
|
||||
continue
|
||||
}
|
||||
|
|
|
|||
|
|
@ -50,4 +50,9 @@ func TestNewLenChars(t *testing.T) {
|
|||
}
|
||||
// Check that only allowed characters are present
|
||||
validateChars(t, u, chars)
|
||||
// Check that two generated strings are different
|
||||
u2 := NewLenChars(length, chars)
|
||||
if u == u2 {
|
||||
t.Fatalf("not unique: %q and %q", u, u2)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue