Documentation ¶
Overview ¶
Package sampler is a golang library for sampling from a slice of items.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Choice ¶
Choice returns a random item from items. If items is empty, Choice panics.
Example ¶
rnd := newFixedRnd() items := []int{1, 2, 3, 4, 5, 6, 7, 8, 9} choice := sampler.Choice(rnd, items) fmt.Println(choice)
Output: 2
func Choices ¶
Choices returns a random selection of n items from items. Items are not guaranteed to be unique.
Example ¶
rnd := newFixedRnd() items := []int{1, 2, 3, 4, 5, 6, 7, 8, 9} choices := sampler.Choices(rnd, items, 3) fmt.Println(choices)
Output: [2 1 3]
func ChoicesAppend ¶
ChoicesAppend returns a random selection of n items from items. Items are appended to dst, which is grown if necessary. Items are not guaranteed to be unique.
func Sample ¶
Sample returns a random selection of n items from items. Items with unique indexes are selected.
[1 2 3 4 5] -> always unique items in result [1 2 3 4 4] -> 4 can be selected twice
Example ¶
rnd := newFixedRnd() items := []int{1, 2, 3, 4, 5, 6, 7, 8, 9} sample := sampler.Sample(rnd, items, 3) fmt.Println(sample)
Output: [2 1 3]
func SampleAppend ¶
SampleAppend returns a random selection of n items from items. Items are appended to dst, which is grown if necessary. Items with unique indexes are selected.
[1 2 3 4 5] -> always unique items in result [1 2 3 4 4] -> 4 can be selected twice