rand

package module
v0.0.0-...-707937a Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 3, 2024 License: BSD-3-Clause Imports: 4 Imported by: 2

README

Rand (Random)

This package is an extension to math/rand, providing cryptographically secure random numbers.

The interface of this package adopts math/rand/v2 and is forward compatible to Go 1.12

This package cannot directly replace math/rand or math/rand/v2, you need to write new code to use this library

RNG (Random Number Generator)

This package uses math/rand as the RNG.

In Go 1.22 and later versions, math/rand/v2 is used as the RNG.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Rand

type Rand struct {
	// contains filtered or unexported fields
}

func (*Rand) ExpFloat64

func (r *Rand) ExpFloat64() float64

func (*Rand) Float32

func (r *Rand) Float32() float32

func (*Rand) Float64

func (r *Rand) Float64() float64

func (*Rand) Int

func (r *Rand) Int() int

func (*Rand) Int32

func (r *Rand) Int32() int32

func (*Rand) Int32N

func (r *Rand) Int32N(n int32) int32

func (*Rand) Int64

func (r *Rand) Int64() int64

func (*Rand) Int64N

func (r *Rand) Int64N(n int64) int64

func (*Rand) IntN

func (r *Rand) IntN(n int) int

func (*Rand) NormFloat64

func (r *Rand) NormFloat64() float64

func (*Rand) Perm

func (r *Rand) Perm(n int) []int

func (*Rand) Shuffle

func (r *Rand) Shuffle(n int, swap func(i int, j int))

func (*Rand) Uint32

func (r *Rand) Uint32() uint32

func (*Rand) Uint32N

func (r *Rand) Uint32N(n uint32) uint32

func (*Rand) Uint64

func (r *Rand) Uint64() uint64

func (*Rand) Uint64N

func (r *Rand) Uint64N(n uint64) uint64

func (*Rand) UintN

func (r *Rand) UintN(n uint) uint

type Rander

type Rander interface {
	Int() int
	IntN(n int) int
	Int32() int32
	Int32N(n int32) int32
	Int64() int64
	Int64N(n int64) int64

	UintN(n uint) uint
	Uint32() uint32
	Uint32N(n uint32) uint32
	Uint64() uint64
	Uint64N(n uint64) uint64

	Float32() float32
	Float64() float64
	ExpFloat64() float64
	NormFloat64() float64

	Perm(n int) []int
	Shuffle(n int, swap func(i int, j int))
}
var (
	Standard Rander = New()
	Crypto   Rander = MustNewCrypto()
)

func MustNewCrypto

func MustNewCrypto() Rander

func New

func New() Rander

func NewCrypto

func NewCrypto(r io.Reader) (Rander, error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL