Documentation
¶
Overview ¶
Package rand provides random number/bytes related functions.
The Rand type is similar to math/rand.Rand, except that it prefers to use crypto/rand to implement functions.
Index ¶
- func Float32() float32
- func Float64() float64
- func Int() int
- func Int31() int32
- func Int31n(n int32) int32
- func Int63() int64
- func Int63n(n int64) int64
- func Intn(n int) int
- func New() (result [16]byte)deprecated
- func NewHex() (result []byte)deprecated
- func Read(p []byte) (n int, err error)
- func Uint() uint
- func Uint32() uint32
- func Uint64() uint64
- type Rand
- 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) Read(p []byte) (n int, err error)
- func (r *Rand) Uint() uint
- func (r *Rand) Uint32() uint32
- func (r *Rand) Uint64() uint64
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Float32 ¶
func Float32() float32
Float32 returns, as a float32, a random number in the half-open interval [0.0,1.0).
func Float64 ¶
func Float64() float64
Float64 returns, as a float64, a random number in the half-open interval [0.0,1.0).
func Int31n ¶
Int31n returns, as an int32, a non-negative random number in the half-open interval [0,n). It panics if n <= 0.
func Int63n ¶
Int63n returns, as an int64, a non-negative random number in the half-open interval [0,n). It panics if n <= 0.
func Intn ¶
Intn returns, as an int, a non-negative random number in the half-open interval [0,n). It panics if n <= 0.
Types ¶
type Rand ¶
type Rand struct {
// contains filtered or unexported fields
}
Rand is similar to "math/rand.Rand", but it prefers "crypto/rand" to generate random bytes.
unlike "math/rand.Rand", all methods of *Rand are safe for concurrent use by multiple goroutines.
func (*Rand) Float32 ¶
Float32 returns, as a float32, a random number in the half-open interval [0.0,1.0).
func (*Rand) Float64 ¶
Float64 returns, as a float64, a random number in the half-open interval [0.0,1.0).
func (*Rand) Int31n ¶
Int31n returns, as an int32, a non-negative random number in the half-open interval [0,n). It panics if n <= 0.
func (*Rand) Int63n ¶
Int63n returns, as an int64, a non-negative random number in the half-open interval [0,n). It panics if n <= 0.
func (*Rand) Intn ¶
Intn returns, as an int, a non-negative random number in the half-open interval [0,n). It panics if n <= 0.
func (*Rand) Read ¶
Read generates len(p) random bytes and writes them into p. It always returns len(p) and a nil error.