mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-01-06 05:01:10 -05:00
Bumps [github.com/gookit/config/v2](https://github.com/gookit/config) from 2.2.3 to 2.2.4. - [Release notes](https://github.com/gookit/config/releases) - [Commits](https://github.com/gookit/config/compare/v2.2.3...v2.2.4) --- updated-dependencies: - dependency-name: github.com/gookit/config/v2 dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com>
38 lines
825 B
Go
38 lines
825 B
Go
package mathutil
|
|
|
|
import (
|
|
"math/rand"
|
|
"time"
|
|
)
|
|
|
|
// RandomInt return a random int at the [min, max)
|
|
//
|
|
// Usage:
|
|
//
|
|
// RandomInt(10, 99)
|
|
// RandomInt(100, 999)
|
|
// RandomInt(1000, 9999)
|
|
func RandomInt(min, max int) int {
|
|
rr := rand.New(rand.NewSource(time.Now().UnixNano()))
|
|
return min + rr.Intn(max-min)
|
|
}
|
|
|
|
// RandInt alias of RandomInt()
|
|
func RandInt(min, max int) int { return RandomInt(min, max) }
|
|
|
|
// RandIntWithSeed alias of RandomIntWithSeed()
|
|
func RandIntWithSeed(min, max int, seed int64) int {
|
|
return RandomIntWithSeed(min, max, seed)
|
|
}
|
|
|
|
// RandomIntWithSeed return a random int at the [min, max)
|
|
//
|
|
// Usage:
|
|
//
|
|
// seed := time.Now().UnixNano()
|
|
// RandomIntWithSeed(1000, 9999, seed)
|
|
func RandomIntWithSeed(min, max int, seed int64) int {
|
|
rr := rand.New(rand.NewSource(seed))
|
|
return min + rr.Intn(max-min)
|
|
}
|