Skip to content

ninedraft/sampler

Go Reference

sampler

Sampler is a golang library for sampling from a slice of items.

Install

go get github.com/ninedraft/sampler

Example usage

import "math/rand/v2" 

var rnd *rand.Rand = ...
items := []int{1, 2, 3, 4, 5, 6, 7, 8, 9}

// acquire a random subset of $items
sample := sampler.Sample(rnd, items, 3)
fmt.Println(sample)
// Output: [8 1 3]


// acquire N random choises from $items
choices := sampler.Choices(rnd, items, 3)
fmt.Println(choices)
// Output: [2 1 1]

// acquire choice a single item from $items
choice := sampler.Choice(rnd, items)
fmt.Println(choice)
// Output: 5

License

APACHE 2.0

About

No description, website, or topics provided.

Resources

License

Apache-2.0, BSD-3-Clause licenses found

Licenses found

Apache-2.0
LICENSE
BSD-3-Clause
LICENSE_go

Stars

Watchers

Forks

Packages

No packages published

Languages