random

package
v2.0.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Jan 3, 2019 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var LockGuardedRand = NewLockedRand()

LockGuardedRand is a global lock protected random source ready to be used.

Functions

func ShuffleStringList

func ShuffleStringList(a []string)

ShuffleStringList shuffles the specified string slice.

func String

func String(sz int) string

String returns a random string with the specified sz length.

Types

type LockedRand

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

LockedRand a mutex protected random source.

func NewLockedRand

func NewLockedRand() *LockedRand

NewLockedRand returns a new LockedRand instance.

func (*LockedRand) Int

func (r *LockedRand) Int() int

Int returns a new random int value.

func (*LockedRand) Uint64

func (r *LockedRand) Uint64() uint64

Uint64 returns a new random uint64 value.

type Probability

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

Probability is used to represent a random probability.

func NewProbability

func NewProbability(outOfMillion uint64) *Probability

NewProbability returns a new Probability instance, the probability is is expressed a outOfMillion / one million, e.g. NewProbability(1) means there is 1 out of 1 million chance.

func (*Probability) Hit

func (p *Probability) Hit() bool

Hit returns a boolean value indicating whether the random event is within the specified random range.

func (*Probability) Missed

func (p *Probability) Missed() bool

Missed returns a boolean value indicating whether the random event is not within the specified random range.

type Source

type Source interface {
	Uint64() uint64
	Int() int
}

Source is the interface for returning random Uint64 and Int values.

Jump to

Keyboard shortcuts

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