Skip to content

lthibault/jitterbug

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

34 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

jitterbug

Tickers with random jitter

Godoc Reference Go Report Card

Jitterbug provides functionality similar to time.Ticker, but with a configurable random jitter.

Jitterbug has no external dependencies, has a stable API, and is production-ready.

Installation

go get -u github.com/lthibault/jitterbug/v2

Usage

Jitterbug is used by instantiating a jitterbug.Ticker with an interval and a jitterbug.Jitter. The former specifies a baseline interval for the ticker, to which a jitter is added by the latter.

package main

import (
    "log"

    "github.com/lthibault/jitterbug"
)

func main() {
    t := jitterbug.New(
        time.Millisecond * 300,
        &jitterbug.Norm{ Stdev: time.Millisecond * 100 },
    )

    // jitterbug.Ticker behaves like time.Ticker
    for tick := range t.C {
        log.Println(tick)
    }
}

Jitterbug is compatible with the univariate distributions from GoNum. For example:

t := jitterbug.New(
    time.Millisecond * 300,
    &jitterbug.Univariate{
        Sampler: &distruv.Gamma{
            // Tip: cast time.Duration as float64 when using gonum's distruv
            Alpha: float64(time.Millisecond * 100),
            Beta:  float64(time.Millisecond * 200),
        }
    },
)

Compatible libraries