From 77bb718c1b0d3554571fb7964e1e296abe4f8413 Mon Sep 17 00:00:00 2001 From: "Derrick J. Wippler" Date: Sun, 30 Jun 2024 06:28:44 -0500 Subject: [PATCH] fix random to include all chars --- random/random.go | 4 ++-- random/random_test.go | 2 ++ set/set.go | 2 +- set/set_test.go | 2 +- 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/random/random.go b/random/random.go index aea1eee..8363f11 100644 --- a/random/random.go +++ b/random/random.go @@ -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) } diff --git a/random/random_test.go b/random/random_test.go index fd3061d..ba452c7 100644 --- a/random/random_test.go +++ b/random/random_test.go @@ -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 { @@ -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 { diff --git a/set/set.go b/set/set.go index 17e9576..2ae9114 100644 --- a/set/set.go +++ b/set/set.go @@ -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. diff --git a/set/set_test.go b/set/set_test.go index 34444bb..e5f191e 100644 --- a/set/set_test.go +++ b/set/set_test.go @@ -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.