syncrand

package
v0.6.5 Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2022 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package syncrand provides synchronized (thread-safe) wrappers of "math/rand".Source64 and "math/rand".Rand.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Global

func Global() *rand.Rand

Global returns this package's global instance of Rand. It is guaranteed to be thread-safe.

func GlobalSource

func GlobalSource() rand.Source64

GlobalSource returns this package's global instance of Source64, which backs the Rand returned by Global(). It is guaranteed to be thread-safe.

func IsThreadSafe added in v0.4.2

func IsThreadSafe(source rand.Source64) bool

IsThreadSafe returns true if its argument is known to be thread-safe.

func New

func New(seed int64) *rand.Rand

New returns a new Rand seeded with the given seed. It is guaranteed to be thread-safe.

func NewFromSource

func NewFromSource(source rand.Source64) *rand.Rand

NewFromSource returns a new Rand that is backed by the given source. It is guaranteed to be thread-safe.

func NewSource

func NewSource(seed int64) rand.Source64

NewSource returns a new Source64 that is seeded with the given seed. It is guaranteed to be thread-safe.

func SetGlobalSource

func SetGlobalSource(source rand.Source64)

SetGlobalSource atomically replaces the global instance of Source64 with the provided one. If it is not thread-safe, then it is wrapped in an implementation of WrappedSource that _is_ thread-safe.

func WrapSource

func WrapSource(source rand.Source64) rand.Source64

WrapSource returns an instance of Source64 that is thread-safe. It may return its argument unchanged, if that argument is already known to be thread-safe.

Types

type WrappedSource added in v0.4.2

type WrappedSource interface {
	rand.Source64
	Unwrap() rand.Source64
}

WrappedSource represents a source of randomness which is itself backed by another source of randomness. The Unwrap() method provides access to the underlying Source.

Jump to

Keyboard shortcuts

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