deterministic

package
v7.6.127 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2024 License: GPL-3.0 Imports: 1 Imported by: 0

Documentation

Overview

Package deterministic is used to make deterministic choices for users.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MakeChoice

func MakeChoice(userID int64, choices ...interface{}) interface{}

MakeChoice makes a choice for the given user ID. This choice is deterministic given constant inputs.

Types

type WeightedChoice

type WeightedChoice interface {
	Weight() int
}

A WeightedChoice represents some choice with an associated weight.

func MakeWeightedChoice

func MakeWeightedChoice(userID int64, choices []WeightedChoice) WeightedChoice

MakeWeightedChoice makes a choice for the given user ID. This choice is deterministic given constant inputs.

To ensure proper distribution of users according to the weights, the following must be true:

(1) The sum of the weights must be less than the maximum assigned user ID.
(2) User IDs must be evenly distributed across their range.

Jump to

Keyboard shortcuts

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