intrange

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Feb 17, 2018 License: MIT Imports: 3 Imported by: 36

Documentation

Overview

Package intrange holds distributions that accept and return ints

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Constant

type Constant int

Constant implements Range as a poll which always returns the same integer.

func (Constant) EnforceRange

func (c Constant) EnforceRange(int) int

EnforceRange on a constant must return the constant

func (Constant) InRange

func (c Constant) InRange(i int) bool

InRange is only valid for a constant if c == i

func (Constant) Mult

func (c Constant) Mult(i float64) Range

Mult returns this range scaled by i

func (Constant) Percentile

func (c Constant) Percentile(float64) int

Percentile can only return the constant itself

func (Constant) Poll

func (c Constant) Poll() int

Poll returns c cast to an int

type Infinite

type Infinite struct{}

Infinite is a immutable range which always polls math.MaxInt32

func (Infinite) EnforceRange

func (inf Infinite) EnforceRange(i int) int

EnforceRange for an Infinite returns Infinite

func (Infinite) InRange

func (inf Infinite) InRange(i int) bool

InRange returns true if i is math.MaxInt32

func (Infinite) Mult

func (inf Infinite) Mult(i float64) Range

Mult does nothing to Infinites.

func (Infinite) Percentile

func (inf Infinite) Percentile(float64) int

Percentile can only return math.MaxInt32

func (Infinite) Poll

func (inf Infinite) Poll() int

Poll returns math.MaxInt32 on Infinites.

type Range

type Range interface {
	Poll() int
	Mult(float64) Range
	InRange(int) bool
	EnforceRange(int) int
	Percentile(float64) int
}

Range represents the ability to poll a struct and return an integer, distributed over some range dependant on the implementing struct.

func NewConstant

func NewConstant(i int) Range

NewConstant returns a range which will always return the input constant

func NewInfinite

func NewInfinite() Range

NewInfinite returns a range which will always return math.MaxInt32 and is unchangable.

func NewLinear

func NewLinear(min, max int) Range

NewLinear returns a linear range between min and max

func NewSpread

func NewSpread(base, s int) Range

NewSpread returns a linear range from base - s to base + s

Jump to

Keyboard shortcuts

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