random

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Jul 13, 2024 License: Apache-2.0, MIT Imports: 11 Imported by: 7

Documentation

Overview

Package random provides functionality to generate pseudo-random test data.

All random numbers and data are created deterministically using a pseudo-random number generator. This generator's output is determined by the value a seed that us set using the current time, or set explicitly.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Addrs

func Addrs(n int) []string

Addrs returns a slice of n random unique addresses.

func BlocksOfSize

func BlocksOfSize(n int, size int) []blocks.Block

BlocksOfSize generates a slice of blocks of the specified byte size.

func Bytes

func Bytes(n int) []byte

Bytes returns a byte array of the given size with random values.

func Cids

func Cids(n int) []cid.Cid

Cids returns a slice of n random unique CIDs.

func HttpMultiaddrs

func HttpMultiaddrs(n int) []multiaddr.Multiaddr

HttpMultiaddrs returns a slice of n random unique Multiaddrs.

func Identity

func Identity() (peer.ID, crypto.PrivKey, crypto.PubKey)

Identity returns a random unique peer ID, private key, and public key.

func Multiaddrs

func Multiaddrs(n int) []multiaddr.Multiaddr

Multiaddrs returns a slice of n random unique Multiaddrs.

func Multihashes

func Multihashes(n int) []multihash.Multihash

Multihashes returns a slice of n random unique Multihashes.

func NewRand added in v0.0.4

func NewRand() *rand.Rand

NewRand returns a new pseudo-random number source, seeded with the next value of a global sequence.

func NewSeededRand added in v0.0.4

func NewSeededRand(seed int64) *rand.Rand

NewSeededRand returns a new pseudo-random number source seeded with the specified value.

func Peers

func Peers(n int) []peer.ID

Peers returns a slice of n random peer IDs.

func Seed

func Seed() int64

Returns the initial seed used for the pseudo-random number generator, or the most recent value set by SetSeed.

func Sequence added in v0.0.3

func Sequence(n int) []uint64

Sequence returns a series of monotonically increasing numbers, starting at the next unique global sequence value. Any current calls to Sequence will not generate any overlapping values.

The sequence numbers themselves are not random, only the global starting value of the sequence numbers is random. This ensures that all sequences generated within a test are unique, assuming < 2^64 values are generated, but start out at a random value.

func SequenceNext added in v0.0.3

func SequenceNext() uint64

SequenceNext returns the next unique global sequence value. This is equivalent to Sequence(1)[0].

func SetSeed

func SetSeed(seed int64)

Sets the seed for the pseudo-random number generator. Calling SetSeed(Seed()) each time before generating random items will cause items with the same values to be generated.

Types

This section is empty.

Jump to

Keyboard shortcuts

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