You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
v2ray-core/common/dice/dice.go

26 lines
500 B

9 years ago
// Package dice contains common functions to generate random number.
// It also initialize math/rand with the time in seconds at launch time.
9 years ago
package dice
import (
"math/rand"
"time"
9 years ago
)
9 years ago
// Roll returns a non-negative number between 0 (inclusive) and n (exclusive).
9 years ago
func Roll(n int) int {
if n == 1 {
return 0
}
return rand.Intn(n)
}
// RandomUint16 returns a random uint16 value.
func RandomUint16() uint16 {
return uint16(rand.Intn(65536))
}
func init() {
rand.Seed(time.Now().Unix())
}