Documentation ¶
Overview ¶
Package ldsampling provides functionality related to sampling.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type RatioSampler ¶
type RatioSampler struct {
// contains filtered or unexported fields
}
RatioSampler provides a simple interface for determining sample selections.
The distribution calculation relies on random number generation, it does not perform any tracking to ensure a strict 1 in x outcome.
A non-positive ratio effectively disables sampling, resulting in Sample always returning false. A ratio of 1 will result in every call being true. Any other ratio results in a 1 in x chance of being sampled.
As a RatioSampler relies on rand.Source, the sampler is not safe for concurrent use.
func NewSampler ¶
func NewSampler() *RatioSampler
NewSampler creates a *RatioSampler instance that can be used to determine sampling selections.
The random number generator used is seeded with the current system time.
func NewSamplerFromSource ¶
func NewSamplerFromSource(source rand.Source) *RatioSampler
NewSamplerFromSource creates a *RatioSampler instance similar to NewSampler with the additional benefit of providing the random number source.
func (*RatioSampler) Sample ¶
func (r *RatioSampler) Sample(ratio int) bool
Sample returns a boolean to determine whether or not something should be sampled. It should not be called concurrently.