-
Notifications
You must be signed in to change notification settings - Fork 18.5k
Closed
Labels
Description
Please answer these questions before submitting your issue. Thanks!
- What version of Go are you using (
go version)?
go version go1.6.1 darwin/amd64 - What operating system and processor architecture are you using (
go env)?
ubuntu server 12.04 - What did you do?
If possible, provide a recipe for reproducing the error.
A complete runnable program is good.
A link on play.golang.org is best.
ps: this func run too many times by many goroutine and just panic once.
// Random [m,n]
func GetRandom(m, n int) int {
if randnum == nil {
randnum = rand.New(rand.NewSource(time.Now().UnixNano()))
}
if m > n {
return 0
}
if m == n {
return m
}
return m + randnum.Intn(n-m+1)
} - What did you expect to see?
return a expect rand int32 - What did you see instead?
panic: runtime error: index out of range
goroutine 1018903 [running]:
panic(0x941da0, 0xc8200100a0)
/usr/local/go/src/runtime/panic.go:464 +0x3e6
math/rand.(_rngSource).Int63(0xc82008d500, 0x0)
/usr/local/go/src/math/rand/rng.go:244 +0xc1
math/rand.(_Rand).Int63(0xc8200e5740, 0x0)
/usr/local/go/src/math/rand/rand.go:46 +0x39
math/rand.(_Rand).Int31(0xc8200e5740, 0xc82469dec8)
/usr/local/go/src/math/rand/rand.go:52 +0x21
math/rand.(_Rand).Int31n(0xc8200e5740, 0x5, 0xc82469dec0)
/usr/local/go/src/math/rand/rand.go:87 +0xc1
math/rand.(*Rand).Intn(0xc8200e5740, 0x5, 0x0)
/usr/local/go/src/math/rand/rand.go:101 +0x92
utils.GetRandom(0x3, 0x7, 0x1)