rand

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2026 License: MIT Imports: 1 Imported by: 0

Documentation

Overview

The rand package provides helpers for utilizing random generated values in automated test cases.

To ensure tests remain deterministic, a constant seed should be used within the test.

const SEED = 42
r := rand.New(SEED)

The motivation behind the rand package is to make tests easier to read by abstracting away arbitrary values. In the following example, we clearly see password is an ASCII string of 30 characters. Its exact value, however, is unimportant for the purpose of testing, so the value remains hidden.

password := r.ASCII(30)

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Rand

type Rand struct {
	*rand.Rand
}

Test helper for generating random test values.

func New

func New(seed int64) Rand

Create a new rand object from a seed. A static seed should be used to ensure deterministic tests.

func (Rand) ASCII

func (r Rand) ASCII(len int) string

Generate a random ASCII string of printable characters.

func (Rand) Bytes

func (r Rand) Bytes(len int) []byte

Generate a random sequence of bytes.

func (Rand) IntRange

func (r Rand) IntRange(min, max int) int

Generate a random int between [min, max] inclusive.

Jump to

Keyboard shortcuts

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