rand

package
v0.0.67 Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2024 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package rand contains utility functions largely for unit testing. WARNING: Do not use the functions in this package that generate rand / seeds for any security related purposes, outside of testing.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetRandomPort

func GetRandomPort() (int32, error)

GetRandomPort returns a random port number. The binding address should not need to be configurable as this is a short-lived operation just to discover a random available port. Note that there is a possible race condition here if another process binds to the same port between the time we discover it and the time we use it. This is unlikely to happen in practice, but if it does, the user will need to retry the command. Marking a nosec here because we want this to listen on all addresses to ensure a reliable connection chance for the client. This is based on lessons learned from the sigstore CLI.

func NewRand

func NewRand(seed int64) *rand.Rand

NewRand returns a new instance of rand.Rand with a fixed source.

func RandomFrom

func RandomFrom[T any](choices []T, seed int64) T

RandomFrom returns an item chosen at random from the given set of alternatives.

func RandomInt

func RandomInt(min, max int64, seed int64) int64

RandomInt returns a random integer between min and max.

func RandomName

func RandomName(seed int64) string

RandomName returns a random name.

func RandomString

func RandomString(n int, seed int64) string

RandomString returns a random string of length n.

Types

This section is empty.

Jump to

Keyboard shortcuts

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