random

package
v0.0.0-...-5352646 Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2020 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package random implements goroutine-safe utilities on top of a secure random source.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Bytes

func Bytes(n int) []byte

Bytes generates a random byte slice of length n. This func uses the global TTNRandom.

func Intn

func Intn(n int) int

Intn returns a random number in the range [0,n). This func uses the global TTNRandom.

func Jitter

func Jitter(d time.Duration, p float64) time.Duration

Jitter returns a random number around d where p is the maximum percentage of change applied to d. With d=100 and p=0.1, the duration returned will be in [90,110].

func Read

func Read(b []byte) (int, error)

Read fills the byte slice with random bytes. This func uses the global TTNRandom.

func String

func String(n int) string

String returns a random string of length n, it uses the characters of base64.URLEncoding. This func uses the global TTNRandom.

Types

type Interface

type Interface interface {
	io.Reader
	Intn(n int) int
	String(n int) string
	Bytes(n int) []byte
}

Interface for random.

func New

func New() Interface

New returns a new Random, in most cases you can also just use the global funcs.

type TTNRandom

type TTNRandom struct {
	io.Reader
}

TTNRandom is used as a wrapper around crypto/rand.

func (*TTNRandom) Bytes

func (r *TTNRandom) Bytes(n int) []byte

Bytes generates a random byte slice of length n.

func (*TTNRandom) Intn

func (r *TTNRandom) Intn(n int) int

Intn returns a random number in the range [0,n).

func (*TTNRandom) String

func (r *TTNRandom) String(n int) string

String returns a random string of length n, it uses the characters of base64.URLEncoding.

Jump to

Keyboard shortcuts

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