Documentation ¶
Overview ¶
Package random provides utilities to complement the math/rand package.
Index ¶
- Variables
- type Interface
- type Mock
- func (m *Mock) ExpFloat64() float64
- func (m *Mock) Float32() float32
- func (m *Mock) Float64() float64
- func (m *Mock) Int() int
- func (m *Mock) Int31() int32
- func (m *Mock) Int31n(n int32) int32
- func (m *Mock) Int63() int64
- func (m *Mock) Int63n(n int64) int64
- func (m *Mock) Intn(n int) int
- func (m *Mock) NormFloat64() float64
- func (m *Mock) Perm(n int) []int
- func (m *Mock) Read(p []byte) (int, error)
- func (m *Mock) Seed(seed int64)
- func (m *Mock) Uint32() uint32
- type ReaderSeeder
- type SeedFunc
- type Seeder
Constants ¶
This section is empty.
Variables ¶
var CryptoSeeder = NewReaderSeeder(cryptorand.Reader)
CryptoSeeder generates seeds using crypto/rand.
var UnixNanoSeeder = SeedFunc(func() (int64, error) { return time.Now().UnixNano(), nil })
UnixNanoSeeder generates seeds with the current nanosecond epoch.
Functions ¶
This section is empty.
Types ¶
type Interface ¶
type Interface interface { Seed(seed int64) ExpFloat64() float64 Float32() float32 Float64() float64 Int() int Int31() int32 Int31n(n int32) int32 Int63() int64 Int63n(n int64) int64 Intn(n int) int NormFloat64() float64 Perm(n int) []int Uint32() uint32 io.Reader }
Interface is an interface for random generators.
func New ¶
func New() Interface
New builds a new random generator (seeded with current nanosecond unix epoch).
func NewFromSeeder ¶
NewFromSeeder builds a new random generator with a seed generated with s.
func NewLocked ¶
NewLocked returns a random source that makes locked calls to the given base random source, making it safe for use with concurrent goroutines.
func NewWithSeed ¶
NewWithSeed builds a random generator with the given seed.
type Mock ¶
Mock is an autogenerated mock type for the Interface type
func (*Mock) ExpFloat64 ¶
ExpFloat64 provides a mock function with given fields:
func (*Mock) NormFloat64 ¶
NormFloat64 provides a mock function with given fields:
type ReaderSeeder ¶
type ReaderSeeder struct {
// contains filtered or unexported fields
}
ReaderSeeder reads seeds from an underlying io.Reader.
func (*ReaderSeeder) Seed ¶
func (r *ReaderSeeder) Seed() (int64, error)
Seed reads 8 bytes from the underlying reader and generates a seed from it.
type SeedFunc ¶
SeedFunc is an adapter to allow ordinary functions to be used as Seeder implementations.
func ConstantSeeder ¶
ConstantSeeder builds a SeedFunc that always returns seed.