Fix randoms

Use seeded mathematical random where uniqueness is needed
but not required to be cryptographic.
This commit is contained in:
Atsushi Watanabe
2020-07-13 13:48:46 +09:00
parent 00f7ed779a
commit 0157f347e4
8 changed files with 34 additions and 25 deletions

View File

@@ -6,14 +6,14 @@ import (
"testing"
)
func TestRandSeq(t *testing.T) {
if len(RandSeq(10)) != 10 {
t.Errorf("RandSeq return invalid length")
func TestMathRandAlpha(t *testing.T) {
if len(MathRandAlpha(10)) != 10 {
t.Errorf("MathRandAlpha return invalid length")
}
var isLetter = regexp.MustCompile(`^[a-zA-Z]+$`).MatchString
if !isLetter(RandSeq(10)) {
t.Errorf("RandSeq should be AlphaNumeric only")
if !isLetter(MathRandAlpha(10)) {
t.Errorf("MathRandAlpha should be AlphaNumeric only")
}
}