stablerand

package
v0.0.0-...-5b88717 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2024 License: BSD-3-Clause Imports: 3 Imported by: 0

Documentation

Overview

Package stablerand is a small helper utility that encapsulates its random engine and always uses the same seed value for its randomness.

This ensures reproducibility and stability across executions, giving a pseudo-random distribution, but with deterministic predictability. This is primarily intended for generating content for tests, which ensures that inputs are still pseudo-random, but predictible and consistent across unchanged executions.

Functions in this package are thread-safe, although use in threaded contexts will remove any guarantees of determinism.

Note: This is primarily used internally for the fhirtest package to implement "random" IDs and meta-IDs so that test resources retain the same general values across executions.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AlnumString

func AlnumString(n int) string

AlnumString returns, as a string, a pseudo-random string containing n alphanumeric characters.

func DecString

func DecString(n int) string

DecString returns, as a string, a pseudo-random string containing n decimal characters.

func HexString

func HexString(n int) string

HexString returns, as a string, a pseudo-random string containing n hex characters.

func Int63n

func Int63n(n int64) int64

Int63n returns, as an int64, a non-negative pseudo-random number in the half-open interval [0,n). It panics if n <= 0.

func Intn

func Intn(n int) int

Intn returns, as an int, a non-negative pseudo-random number in the half-open interval [0,n). It panics if n <= 0.

func OneOf

func OneOf[T any](args ...T) T

OneOf returns, as a T object, a pseudo-randomly selected value from args. It panics if args is empty.

func String

func String(n int, alphabet string) string

String returns, as a string, a pseudo-random string containing n characters all consisting of values within the supplied alphabet string. It panics if the alphabet string is empty.

func Time

func Time(base time.Time, variation time.Duration) time.Time

Time returns, as a time.Time object, a pseudo-random time starting with the base time, and adding a random amount between the half-open interval [0, variation) to the time. It panics if variation is negative.

Types

This section is empty.

Jump to

Keyboard shortcuts

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