// 该函数设置随机种子
// 若不调用此函数设置随机种子,则默认的种子值为1,由于随机算法是固定的,
// 如果每次都以1作为随机种子开始产生随机数,则结果都是一样的,因此一般
// 都需要调用此函数来设置随机种子,通常的做法是以当前时间作为随机种子
// 以保证每次随机种子都不同,从而产生的随机数也不通
// 该函数协程安全
func Seed(seed int64)
// 以下函数用来生成相应数据类型的随机数,带n的版本则生成[0,n)的随机数。
// 注意生成的随机数都是非负数
func Float32() float32
func Float64() float64
func Int() int
func Int31() int32 // 注意该函数只返回int32表示范围内的非负数,位数为31,因此该函数叫做Int31
func Int31n(n int32) int32
func Int63() int64
func Int63n(n int64) int64
func Intn(n int) int
func Uint32() uint32
func Uint64() uint64
// 另外,rand包还提供了一个类,接口和上面的大致相同:
type Rand struct {
// ...
}
// 创建一个以seed为种子的源,注意该源不是协程安全的
func NewSource(seed int64) Source
// 以src为源创建随机对象
func New(src Source) *Rand
// 设置或重置种子,注意该函数不是协程安全的
func (r *Rand) Seed(seed int64)
// 下面的函数和全局版本的函数功能一样
func (r *Rand) Float32() float32
func (r *Rand) Float64() float64
func (r *Rand) Int() int
func (r *Rand) Int31() int32
func (r *Rand) Int31n(n int32) int32
func (r *Rand) Int63() int64
func (r *Rand) Int63n(n int64) int64
func (r *Rand) Intn(n int) int
func (r *Rand) Uint32() uint32
func (r *Rand) Uint64() uint64