diff --git a/uniuri_test.go b/uniuri_test.go index c9c3ffb..0e26efe 100644 --- a/uniuri_test.go +++ b/uniuri_test.go @@ -83,3 +83,20 @@ func TestNewLenCharsMaxLength(t *testing.T) { chars := make([]byte, 257) NewLenChars(32, chars) } + +func TestBias(t *testing.T) { + chars := []byte("abcdefghijklmnopqrstuvwxyz") + slen := 100000 + s := NewLenChars(slen, chars) + counts := make(map[rune]int) + for _, b := range s { + counts[b]++ + } + avg := float64(slen) / float64(len(chars)) + for k, n := range counts { + diff := float64(n) / avg + if diff < 0.95 || diff > 1.05 { + t.Errorf("Bias on '%c': expected average %f, got %d", k, avg, n) + } + } +}