summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--pkg/helpers/utils.go4
-rw-r--r--pkg/helpers/utils_test.go10
2 files changed, 12 insertions, 2 deletions
diff --git a/pkg/helpers/utils.go b/pkg/helpers/utils.go
index 1a3f411..35de2c3 100644
--- a/pkg/helpers/utils.go
+++ b/pkg/helpers/utils.go
@@ -7,7 +7,7 @@ import (
)
var characterRunes = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789")
-var src = rand.NewSource(time.Now().UnixNano())
+var r = rand.New(rand.NewSource(time.Now().UnixNano()))
// TrimTrailingNewline removes the trailing new line form a string. this method
// is used mostly on outputs of a command
@@ -30,7 +30,7 @@ func Min(x, y int) int {
func RandomString(n int) string {
b := make([]rune, n)
for i := range b {
- b[i] = characterRunes[rand.Intn(len(characterRunes))]
+ b[i] = characterRunes[r.Intn(len(characterRunes))]
}
return string(b)
}
diff --git a/pkg/helpers/utils_test.go b/pkg/helpers/utils_test.go
new file mode 100644
index 0000000..4b48d3c
--- /dev/null
+++ b/pkg/helpers/utils_test.go
@@ -0,0 +1,10 @@
+package helpers
+
+import "testing"
+
+func TestRandomString(t *testing.T) {
+ var rand_string = RandomString(8)
+ if len(rand_string) != 8 {
+ t.Errorf("The length of the string should be equal.")
+ }
+}