diff options
Diffstat (limited to 'utils/random.go')
-rw-r--r-- | utils/random.go | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/utils/random.go b/utils/random.go new file mode 100644 index 000000000..ca2ace949 --- /dev/null +++ b/utils/random.go @@ -0,0 +1,20 @@ +// Copyright (c) 2015 Spinpunch, Inc. All Rights Reserved. +// See License.txt for license information. + +package utils + +import ( + "math/rand" +) + +type Range struct { + Begin int + End int +} + +func RandIntFromRange(r Range) int { + if r.End-r.Begin <= 0 { + return r.Begin + } + return rand.Intn((r.End-r.Begin)+1) + r.Begin +} |