ldsampling

package
v4.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2026 License: Apache-2.0 Imports: 2 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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.

Jump to

Keyboard shortcuts

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