utils

package
v0.0.0-...-ce97658 Latest Latest
Warning

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

Go to latest
Published: Mar 17, 2024 License: Apache-2.0 Imports: 2 Imported by: 10

README

utils: various helpful helpers

This package contains a number of useful and commonly used functions and structures.

  • Ranges (Float, Int)
  • Moving and weighted average
  • Min, max, abs for integers
  • Normalized random number (gaussian)

TODO

  • Expose functions with custom rand sources

Documentation

Overview

Package utils provides some commonly used functionality.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Abs

func Abs(a int) int

Abs is the int equivalent of math.Abs(a).

func Gauss

func Gauss(mean, stdDev float64) float64

Gauss returns a normally distributed random number with the given mean and standard deviation. NOTE: mean: mu, stdDev: sigma See: https://en.wikipedia.org/wiki/Normal_distribution

func IncrementalAvrg

func IncrementalAvrg(oldVal, newVal float64, count int) float64

IncrementalAvrg computes the incremental average given the old value, the new value and the previous number of samples.

func Max

func Max(a, b int) int

Max is the int equivalent of math.Max(a, b).

func Min

func Min(a, b int) int

Min is the int equivalent of math.Min(a, b).

func MinMax

func MinMax[V Number](values []V) (min, max V)

MinMax returns the minimum and maximum value of the given slice.

func WeightedAvrg

func WeightedAvrg(oldVal, newVal, weightFactor float64) float64

WeightedAvrg computes the weighted average given the old value, the new value and the weight factor.

Types

type FloatRange

type FloatRange [2]float64

FloatRange represents a minimum and maximum value.

func (FloatRange) InRange

func (r FloatRange) InRange(value float64) bool

InRange returns true if the given value is within the range.

func (FloatRange) Max

func (r FloatRange) Max() float64

Max FloatRange the maximum value of the range.

func (FloatRange) Min

func (r FloatRange) Min() float64

Min returns the minimum value of the range.

func (FloatRange) Random

func (r FloatRange) Random() float64

Random returns a random value between min and max.

type IntRange

type IntRange [2]int

IntRange represents a minimum and maximum value.

func (IntRange) InRange

func (r IntRange) InRange(value int) bool

InRange returns true if the given value is within the range.

func (IntRange) Max

func (r IntRange) Max() int

Max returns the maximum value of the range.

func (IntRange) Min

func (r IntRange) Min() int

Min returns the minimum value of the range.

func (IntRange) Random

func (r IntRange) Random() int

Random returns a random value between min and max.

type Number

type Number interface {
	int | int64 | float64
}

Number is the interface for some numeric types.

type Rand63

type Rand63 func() int64

Type alias for rand.Int63().

type RandFloat64

type RandFloat64 func() float64

Type alias for rand.Float64().

type RandIntn

type RandIntn func(int) int

Type alias for rand.Intn().

Jump to

Keyboard shortcuts

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