random

package module
v0.0.0-...-3737a3b Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2016 License: BSD-3-Clause Imports: 7 Imported by: 10 modules, 10 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

maturity build status code coverage GoDoc

random

The random package implements a service to generate pseudo random numbers.

Documentation

Overview

Package random provides a service implementation creating random numbers.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Bit

func Bit() int

Bit returns a pseudo random bit value that is either 0 or 1.

func IsInvalidConfig

func IsInvalidConfig(err error) bool

IsInvalidConfig asserts invalidConfigError.

func IsTimeout

func IsTimeout(err error) bool

IsTimeout asserts timeoutError.

Types

type Backoff

type Backoff interface {
	// NextBackOff provides the duration expected to wait before retrying an
	// action. time.Duration = -1 indicates that no more retry should be
	// attempted.
	NextBackOff() time.Duration
	// Reset sets the backoff back to its initial state.
	Reset()
}

Backoff represents the object managing backoff algorithms to retry actions.

type Service

type Service interface {
	// CreateMax tries to create one new pseudo random number. The generated
	// number is within the range [0 max), which means that max is exclusive.
	CreateMax(max int) (int, error)
	// CreateNMax tries to create a list of new pseudo random numbers. n
	// represents the number of pseudo random numbers in the returned list. The
	// generated numbers are within the range [0 max), which means that max is
	// exclusive.
	CreateNMax(n, max int) ([]int, error)
}

Service creates pseudo random numbers. The service might implement retries using backoff strategies and timeouts.

func NewService

func NewService(config ServiceConfig) (Service, error)

NewService creates a new configured random service.

type ServiceConfig

type ServiceConfig struct {

	// BackoffFactory is supposed to be able to create a new spec.Backoff. Retry
	// implementations can make use of this to decide when to retry.
	BackoffFactory func() Backoff
	// RandFactory represents a service returning random values. Here e.g.
	// crypto/rand.Int can be used.
	RandFactory func(rand io.Reader, max *big.Int) (n *big.Int, err error)

	// RandReader represents an instance of a cryptographically strong
	// pseudo-random generator. Here e.g. crypto/rand.Reader can be used.
	RandReader io.Reader
	// Timeout represents the deadline being waited during random number creation
	// before returning a timeout error.
	Timeout time.Duration
}

ServiceConfig represents the configuration used to create a new random service.

func DefaultServiceConfig

func DefaultServiceConfig() ServiceConfig

DefaultServiceConfig provides a default configuration to create a new random service by best effort.

Jump to

Keyboard shortcuts

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