Package reservoir samples values uniformly at random from an unbounded sequence of inputs

Package reservoir samples values uniformly at random
from an unbounded sequence of inputs.

import "kr.dev/reservoir"

For instance, errors. If you have more errors than
you know what to do with, and you can't read them all
or even store them all, and you want to get a rough
idea of what is going on, here's how you could do it:

	rs := reservoir.New[error](100)
	...
	rs.Add(err) // add errors
	...
	rs.Add(err) // unlimited amount of errors
	...
	errs := make([]error, rs.Cap())
	n := rs.Read(errs)
	fmt.Println("sampled:", errs[:n])

This will print up to 100 error values, sampled
uniformly, without replacement, from the sequence
of all errors that have been added to rs so far.
Similar Resources

Random fake data generator written in go

Random fake data generator written in go

Gofakeit Random data generator written in go Features 160+ Functions!!! Concurrent Global Rand Struct Generator Custom Functions Http Server Command L

Jan 1, 2023

Generate random, pronounceable, sometimes even memorable, "superhero like" codenames - just like Docker does with container names.

Codename an RFC1178 implementation to generate pronounceable, sometimes even memorable, "superheroe like" codenames, consisting of a random combinatio

Dec 11, 2022

A repository of random code snippets used to develop proof of concepts

Oddments Oddments is a repository of random code snippets used to develop proof of concepts for techniques used with the Windows operating system. POC

Oct 13, 2022

Helps exercise your memory by giving you random tokens and poems to memorize.

memory-enhancer Helps exercise your memory by giving you random tokens and poems to memorize. Using Every day when you first open your terminal you wi

Nov 9, 2021

Randomdata : a tiny help suite for generating random data

go-randomdata randomdata is a tiny help suite for generating random data such as first names (male or female) last names full names (male or female) c

Dec 5, 2021

Rfpm - Random Fair Preemption Model For Golang

rfpm RFPM (Random Fair Preemption Model) is absolutely fair to all clients who r

Jan 7, 2022

:sunglasses:Package captcha provides an easy to use, unopinionated API for captcha generation

Package captcha provides an easy to use, unopinionated API for captcha generation. Why another captcha generator? I want a simple and framework-indepe

Dec 28, 2022

A Go package that reports processor topology

Description ------------ cpu package reports (some) processor topology information Note that the term package refers to a physical processor

Nov 5, 2022

A simple debugging Go package to perform Dump and Die

dump A simple Go package to perform Dump and Die.

May 16, 2021
A command line tool to generate sequence diagrams
A command line tool to generate sequence diagrams

goseq - text based sequence diagrams A small command line utility used to generate UML sequence diagrams from a text-base definition file. Inspired by

Dec 22, 2022
I'm sick. And... fibonacci sequence.
I'm sick. And... fibonacci sequence.

Fibonacci Sequence Like I said, Fibonnaci Sequence. Be happy that I didn't make any more fuss about this "achievement" (it's not, for anyone) Source c

Oct 18, 2021
A Github action to check if IDT could synthesize a given DNA sequence.

dna-is-synthesizable A github action to check if a part is synthesizable from a given Genbank file. dna-is-synthesizable is a Github Action that recei

Oct 28, 2021
seqinfo gathers image sequence info from directories.

seqinfo seqinfo gathers info from sequences in directories, and prints or writes it to an excel file. Usage seqinfo /path/to/search/sequences For adv

Dec 23, 2021
Snowflake algorithm generation worker Id sequence

sequence snowflake algorithm generation worker Id sequence 使用雪花算法生成ID,生成100万个只需要

Jan 21, 2022
Go package and associated command line utility to generate random yet human-readable names and identifiers
Go package and associated command line utility to generate random yet human-readable names and identifiers

namegen | What's this? Go package and associated command line utility to generate random yet human-readable names and identifiers. Somewhat inspired b

Oct 19, 2022
Initialize structs with default values

defaults Initialize structs with default values Supports almost all kind of types Scalar types int/8/16/32/64, uint/8/16/32/64, float32/64 uintptr, bo

Jan 7, 2023
Best-effort CPU-local sharded values for Go
Best-effort CPU-local sharded values for Go

percpu Percpu is a Go package to support best-effort CPU-local sharded values. This package is something of an experiment. See Go issue #18802 for dis

Nov 9, 2022
Type-safe atomic values for Go

Type-safe atomic values for Go One issue with Go's sync/atomic package is that there is no guarantee from the type system that operations on an intege

Apr 8, 2022
Random fake data and struct generator for Go.

Faker Random fake data and struct generator for Go. More than 100 generator functions Struct generator Unique data generator Builtin types support Eas

Oct 3, 2022