random

package
v2.0.0-alpha.64 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2026 License: Apache-2.0 Imports: 6 Imported by: 1 module, 0 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.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Bool

func Bool(ctx context.Context) (runtime.Value, error)

bool draws a non-cryptographic pseudo-random Boolean from the Session source. @return {Boolean} True or false with equal probability, consuming the shared random sequence.

func Choice

func Choice(ctx context.Context, values runtime.Value) (runtime.Value, error)

choice selects one uniformly distributed value using the Session's pseudo-random source. Reservoir sampling takes O(n) time and O(1) additional storage. @param values {Any[]} Input list, traversed once without copying or modifying it. @return {Any} One original value, or None for an empty list. Empty and singleton lists consume no randomness. @throws {TypeError} The argument is not a List.

func Float

func Float(ctx context.Context, args ...runtime.Value) (runtime.Value, error)

Float draws a pseudo-random Float with zero or two numeric bounds. Ranged draws use [min, max); equal bounds return Float(min) without advancing the RNG. Non-finite bounds and unequal intervals containing no Float are invalid.

func Int

func Int(ctx context.Context, min, max runtime.Value) (runtime.Value, error)

int draws a non-cryptographic pseudo-random integer between inclusive bounds. @param min {Int} Inclusive lower bound; must not exceed max. Floats are not coerced. @param max {Int} Inclusive upper bound, including the maximum supported Int. @return {Int} A uniformly distributed integer in [min, max]. Equal bounds return min without drawing. @throws {TypeError} A bound is not an Int. @throws {InvalidArgument} The minimum exceeds the maximum.

func RegisterLib

func RegisterLib(ns runtime.Namespace)

RegisterLib registers non-cryptographic random value generation. These functions are unsuitable for passwords, authentication tokens, or secrets. @namespace random

func Shuffle

func Shuffle(ctx context.Context, values runtime.Value) (_ runtime.Value, err error)

shuffle randomizes the input values using the Session's pseudo-random source. Materialization and Fisher-Yates use O(n) append/swap operations; their cost and the destination's storage depend on the source's collection backend. @param values {List} Input list, traversed once and never modified. Its factory creates the destination; values retain their identity. @return {List} A new list preserving the source's implementation family and backend configuration, containing the original values in randomized order. Empty and singleton lists consume no randomness. @throws {TypeError} The argument is not a List.

Types

This section is empty.

Jump to

Keyboard shortcuts

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