Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewMasterseed ¶
NewMasterseed Compute a uniformly random series of 32 bytes.
Errors if the underlying generator does not have sufficient entropy.
func NewNonce ¶
NewNonce Compute a uniformly random uint64.
Errors if the underlying generator does not have sufficient entropy.
Types ¶
type Uniform ¶
type Uniform struct { N int // contains filtered or unexported fields }
Uniform implements the Sampler interface by using the uniform distribution in the range [0, N). All operations run in O(1) time.
func (*Uniform) SampleReplace ¶
SampleReplace implements the Sampler interface
type Weighted ¶
type Weighted struct { Weights []uint64 // contains filtered or unexported fields }
Weighted implements the Sampler interface by sampling based on a heap structure.
Node weight is defined as the node's given weight along with it's children's recursive weights. Once sampled, a nodes given weight is set to 0.
Replacing runs in O(n) time while sampling runs in O(log(n)) time.
func (*Weighted) Replace ¶
func (s *Weighted) Replace()
Replace all the sampled elements. Takes O(len(weights)) time.
func (*Weighted) Sample ¶
Sample returns a number in [0, len(weights)) with probability proportional to the weight of the item at that index. Assumes Len > 0. Sample takes O(log(len(weights))) time.
func (*Weighted) SampleReplace ¶
SampleReplace returns a number in [0, len(weights)) with probability proportional to the weight of the item at that index. Assumes CanSample returns true. Sample takes O(log(len(weights))) time. The returned index is not removed.