randomkit

package module
v0.0.0-...-ae981c2 Latest Latest
Warning

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

Go to latest
Published: Sep 2, 2024 License: MIT Imports: 3 Imported by: 1

README

randomkit GoDoc Coverage Status

randomkit is a Go package for random number generation.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Binomial

func Binomial(n int, p float64, size int) []int

Binomial returns a slice of Xs drawn from a Binomial(n, p) distribution.

func Kahan

func Kahan(a []float64) float64

Kahan implements the Kahan Summation Algorithm: https://en.wikipedia.org/wiki/Kahan_summation_algorithm

func Multinomial

func Multinomial(n int, probs []float64, retSize int) []int

Multinomial returns a slice of ints drawn from the probabilities provided.

Types

type BinomialGenerator

type BinomialGenerator struct {
	sync.Mutex
	*rand.Rand
}

BinomialGenerator is a random number generator built on top of math/rand. It generates a value ~ binomial(n, p)

func (*BinomialGenerator) Int

func (g *BinomialGenerator) Int(n int, p float64) int

Int returns X ~ binomial(n, p) as an int

n = number of tries p = probability of acceptance

if n > 1000, the process used to generate the result is concurrent.

func (*BinomialGenerator) Int64

func (g *BinomialGenerator) Int64(n int64, p float64) int64

Int64 returns X ~ binomial(n, p) as an int64

n = number of tries p = probability of acceptance

if n > 1000, the process used to generate the result is concurrent.

func (*BinomialGenerator) Multinomial

func (g *BinomialGenerator) Multinomial(n int, probs []float64, retSize int) []int

Jump to

Keyboard shortcuts

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