random

package
v0.0.0-...-79eae96 Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2024 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var NextSeed = func() func() int64 {
	seedsChan := make(chan int64)
	go func() {
		const BytesPerUint64 = 8
		var (
			n    = 100
			data = make([]byte, (n * BytesPerUint64))
		)
		for {
			_, err := rand.Read(data)
			if err != nil {
				panic(err)
			}
			for i := 0; i < n; i++ {
				bs := data[(i * BytesPerUint64):]
				u := binary.BigEndian.Uint64(bs)
				u = (u << 1) >> 1
				seedsChan <- int64(u)
			}
		}
	}()
	return func() int64 {
		return <-seedsChan
	}
}()

Functions

func RandBool

func RandBool(r *Rand) bool

func RandByCorpus

func RandByCorpus[T any](r *Rand, vs []T) T

func Shuffle

func Shuffle(r *Rand, sw Swapper)

Types

type Bit

type Bit = uint

func RandBit

func RandBit(r *Rand) Bit

type Rand

type Rand = rand.Rand

func NewRandNow

func NewRandNow() *Rand

func NewRandSeed

func NewRandSeed(seed int64) *Rand

func NewRandTime

func NewRandTime(t time.Time) *Rand

func NextRand

func NextRand() *Rand

type Random

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

func NewRandom

func NewRandom(baseRand *Rand) *Random

func (*Random) Bit

func (r *Random) Bit() Bit

func (*Random) Bool

func (r *Random) Bool() bool

func (*Random) Byte

func (r *Random) Byte() byte

func (*Random) Rand

func (r *Random) Rand() *Rand

func (*Random) Uint32

func (r *Random) Uint32() uint32

func (*Random) Uint64

func (r *Random) Uint64() uint64

type Swapper

type Swapper interface {
	Len() int
	Swap(i, j int)
}

Jump to

Keyboard shortcuts

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