Merge pull request #13112 from jen20/acctest-random-int-range

helper/acctest: Add RandIntRange helper function
This commit is contained in:
Jake Champlin 2017-03-28 10:14:33 -04:00 committed by GitHub
commit 6d99dc5466
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() 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 // RandString generates a random alphanumeric string of the length specified
func RandString(strlen int) string { func RandString(strlen int) string {
return RandStringFromCharSet(strlen, CharSetAlphaNum) return RandStringFromCharSet(strlen, CharSetAlphaNum)