helper/acctest: Add RandIntRange helper function

This commit adds a new RandIntRange function to the helper/acctest
package for generating random integers in a given range. This is useful
when randomizing test spaces with a constrained range (e.g. 0-4095).
This commit is contained in:
James Nugent 2017-03-22 17:53:49 -05:00
parent 23968a860f
commit 5d734cee4e
1 changed files with 8 additions and 0 deletions

View File

@ -24,6 +24,14 @@ func RandInt() int {
return rand.New(rand.NewSource(time.Now().UnixNano())).Int()
}
func RandIntRange(min int, max int) int {
reseed()
source := rand.New(rand.NewSource(time.Now().UnixNano()))
rangeMax := max - min
return int(source.Int31n(int32(rangeMax)))
}
// RandString generates a random alphanumeric string of the length specified
func RandString(strlen int) string {
return RandStringFromCharSet(strlen, CharSetAlphaNum)