Skip to content

Commit

Permalink
fix random to include all chars
Browse files Browse the repository at this point in the history
  • Loading branch information
thrawn01 committed Jun 30, 2024
1 parent 16bda74 commit 77bb718
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 4 deletions.
4 changes: 2 additions & 2 deletions random/random.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ func Runes(prefix string, length int, runes ...string) string {
chars := strings.Join(runes, "")
var bytes = make([]byte, length)

for i, _ := range bytes {
bytes[i] = chars[rand.Intn(len(runes))]
for i := range bytes {
bytes[i] = chars[rand.Intn(len(chars))]
}
return prefix + string(bytes)
}
Expand Down
2 changes: 2 additions & 0 deletions random/random_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ func TestString(t *testing.T) {
}} {
t.Run(tc.msg, func(t *testing.T) {
res := random.String(tc.prefix, tc.length)
t.Logf("Random String: %s", res)
assert.Equal(t, tc.expectedLength, len(res))
assert.Contains(t, res, tc.prefix)
for _, ch := range res {
Expand Down Expand Up @@ -61,6 +62,7 @@ func TestAlpha(t *testing.T) {
}} {
t.Run(tc.msg, func(t *testing.T) {
res := random.Alpha(tc.prefix, tc.length)
t.Logf("Random Alpha: %s", res)
assert.Equal(t, tc.expectedLength, len(res))
assert.Contains(t, res, tc.prefix)
for _, ch := range res {
Expand Down
2 changes: 1 addition & 1 deletion set/set.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2024 Kapetan.io Technologies
Copyright 2024 Derrick J Wippler
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion set/set_test.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2024 Kapetan.io Technologies
Copyright 2024 Derrick J Wippler
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down

0 comments on commit 77bb718

Please sign in to comment.