2016-02-03 16:49:38 -05:00
|
|
|
// Package dice contains common functions to generate random number.
|
|
|
|
// It also initialize math/rand with the time in seconds at launch time.
|
|
|
|
|
2016-01-21 16:45:44 -05:00
|
|
|
package dice
|
|
|
|
|
|
|
|
import (
|
|
|
|
"math/rand"
|
2016-01-25 05:47:22 -05:00
|
|
|
"time"
|
2016-01-21 16:45:44 -05:00
|
|
|
)
|
|
|
|
|
2016-02-03 16:49:38 -05:00
|
|
|
// Roll returns a non-negative number between 0 (inclusive) and n (exclusive).
|
2016-01-21 16:45:44 -05:00
|
|
|
func Roll(n int) int {
|
|
|
|
if n == 1 {
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
return rand.Intn(n)
|
|
|
|
}
|
2016-01-25 05:47:22 -05:00
|
|
|
|
|
|
|
func init() {
|
|
|
|
rand.Seed(time.Now().Unix())
|
|
|
|
}
|