Help us shape the future of Go! Take the 2026 Go Developer Survey

alias

package module
v0.0.0-...-4f70d72 Latest Latest
Warning

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

Go to latest
Published: Dec 10, 2015 License: BSD-2-Clause Imports: 3 Imported by: 0

README

This package implements the alias method of random number generation for an arbitrary discrete distribution.

You can install it with:

go get github.com/encryptio/alias

Documentation

Overview

The alias package picks items from a discrete distribution efficiently using the alias method.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Alias

type Alias struct {
	// contains filtered or unexported fields
}

func New

func New(prob []float64) (*Alias, error)

Create a new alias object. For example,

var v = alias.New([]float64{8,10,2})

creates an alias that returns 0 40% of the time, 1 50% of the time, and 2 10% of the time.

func (*Alias) Gen

func (al *Alias) Gen(rng *rand.Rand) uint32

Generates a random number according to the distribution using the rng passed.

func (*Alias) MarshalBinary

func (al *Alias) MarshalBinary() ([]byte, error)

MarshalBinary implements encoding.BinaryMarshaller.

func (*Alias) UnmarshalBinary

func (al *Alias) UnmarshalBinary(p []byte) error

UnmarshalBinary implements encoding.BinaryUnmarshaller.

Jump to

Keyboard shortcuts

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