Documentation
¶
Overview ¶
Package random provides functionality to generate pseudo-random test data.
All random numbers and data are created deterministically using the ChaCha8 pseudo-random number generator. This generator's output is determined by a seed value that can be set explicitly. If not set, then cryptographically secure random data is used as the seed.
Index ¶
- func AddrInfos(numPeers, numAddrs int) []peer.AddrInfo
- func Addrs(n int) []string
- func BlocksOfSize(n int, size int64) []blocks.Block
- func Bytes(n int64) []byte
- func Cids(n int) []cid.Cid
- func DnsAddrInfos(numPeers, numAddrs int) []peer.AddrInfo
- func DnsAddrs(n int) []string
- func DnsMultiaddrs(n int) []multiaddr.Multiaddr
- func HttpAddrInfos(numPeers, numAddrs int) []peer.AddrInfo
- func HttpDnsAddrInfos(numPeers, numAddrs int) []peer.AddrInfo
- func HttpDnsMultiaddrs(n int) []multiaddr.Multiaddr
- func HttpMultiaddrs(n int) []multiaddr.Multiaddr
- func Identity() (peer.ID, crypto.PrivKey, crypto.PubKey)
- func Multiaddrs(n int) []multiaddr.Multiaddr
- func Multihashes(n int) []multihash.Multihash
- func Name(size int) string
- func NameSize(minSize, maxSize int) string
- func NewSeed() [32]byte
- func Peers(n int) []peer.ID
- func StringToSeed(s string) [32]byte
- func Uint64ToSeed(val uint64) [32]byte
- type Random
- func (r *Random) AddrInfos(numPeers, numAddrs int) []peer.AddrInfo
- func (r *Random) Addrs(n int) []string
- func (r *Random) BlocksOfSize(n int, size int64) []blocks.Block
- func (r *Random) Bytes(n int64) []byte
- func (r *Random) Cids(n int) []cid.Cid
- func (r *Random) DnsAddrInfos(numPeers, numAddrs int) []peer.AddrInfo
- func (r *Random) DnsAddrs(n int) []string
- func (r *Random) DnsMultiaddrs(n int) []multiaddr.Multiaddr
- func (r *Random) HttpAddrInfos(numPeers, numAddrs int) []peer.AddrInfo
- func (r *Random) HttpDnsAddrInfos(numPeers, numAddrs int) []peer.AddrInfo
- func (r *Random) HttpDnsMultiaddrs(n int) []multiaddr.Multiaddr
- func (r *Random) HttpMultiaddrs(n int) []multiaddr.Multiaddr
- func (r *Random) Identity() (peer.ID, crypto.PrivKey, crypto.PubKey)
- func (r *Random) Multiaddrs(n int) []multiaddr.Multiaddr
- func (r *Random) Multihashes(n int) []multihash.Multihash
- func (r *Random) Name(size int) string
- func (r *Random) NameSize(minSize, maxSize int) string
- func (r *Random) Peers(n int) []peer.ID
- func (r *Random) Read(p []byte) (n int, err error)
- func (r *Random) Seed(seed [32]byte)
- type Sequence
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddrInfos ¶ added in v0.3.0
AddrInfos returns a slice AddrInfo with numPeers elements. Each AddrInfo has a unique ID and numAddrs Addresses. The multiaddrs are ipv4 addresses.
Creates its own random source; safe for concurrent use.
func Addrs ¶
Addrs returns a slice of n random unique IPv4 addresses.
Creates its own random source; safe for concurrent use.
func BlocksOfSize ¶
BlocksOfSize generates a slice of blocks of the specified byte size.
Creates its own random source; safe for concurrent use.
func Bytes ¶
Bytes returns a byte array of the given size with random values.
Creates its own random source; safe for concurrent use.
func Cids ¶
Cids returns a slice of n random unique CIDs.
Creates its own random source; safe for concurrent use.
func DnsAddrInfos ¶ added in v0.3.0
DnsAddrInfos returns a slice AddrInfo with numPeers elements. Each AddrInfo has a unique ID and numAddrs Addresses. The multiaddrs are dns addresses.
Creates its own random source; safe for concurrent use.
func DnsAddrs ¶ added in v0.3.0
DnsAddrs returns a slice of n random unique DNS addresses in the format "xxxxxxxx.example.com:port".
Creates its own random source; safe for concurrent use.
func DnsMultiaddrs ¶ added in v0.3.0
DnsMultiaddrs returns a slice of n random unique Multiaddrs with dns addresses.
Creates its own random source; safe for concurrent use.
func HttpAddrInfos ¶ added in v0.3.0
HttpAddrInfos returns a slice AddrInfo with numPeers elements. Each AddrInfo has a unique ID and numAddrs Addresses. The multiaddrs are ipv4 addresses with http protocol
Creates its own random source; safe for concurrent use.
func HttpDnsAddrInfos ¶ added in v0.3.0
HttpDnsAddrInfos returns a slice AddrInfo with numPeers elements. Each AddrInfo has a unique ID and numAddrs Addresses. The multiaddrs are dns addresses with http protocol.
Creates its own random source; safe for concurrent use.
func HttpDnsMultiaddrs ¶ added in v0.3.0
HttpDnsMultiaddrs returns a slice of n random unique Multiaddrs with dns addresses and http protocol.
Creates its own random source; safe for concurrent use.
func HttpMultiaddrs ¶
HttpMultiaddrs returns a slice of n random unique Multiaddrs with ipv4 addresses and http protocol.
Creates its own random source; safe for concurrent use.
func Identity ¶
Identity returns a random unique peer ID, private key, and public key.
Creates its own random source; safe for concurrent use.
func Multiaddrs ¶
Multiaddrs returns a slice of n random unique Multiaddrs with ipv4 addresses.
Creates its own random source; safe for concurrent use.
func Multihashes ¶
Multihashes returns a slice of n random unique Multihashes.
Creates its own random source; safe for concurrent use.
func Name ¶ added in v0.4.0
Name returns a string of n random lower-alphanumeric characters.
Creates its own random source; safe for concurrent use.
func NameSize ¶ added in v0.4.0
NameSize returns a string of random lower-alphanumeric characters, having a random size of at least minSize and at most maxSize.
Creates its own random source; safe for concurrent use.
func NewSeed ¶ added in v0.4.0
func NewSeed() [32]byte
NewSeed creates a new random seed for use in seeding creating random sources with the same seed value using NewSeeded.
func Peers ¶
Peers returns a slice of n random peer IDs.
Creates its own random source; safe for concurrent use.
func StringToSeed ¶ added in v0.4.0
StringToSeed creates a seed value from a string. The string is hashed so that if the string is longer than the necessary seed data, the entire string contributes to the seed value.
func Uint64ToSeed ¶ added in v0.4.0
Uint64ToSeed creates a seed value from a uint64 value.
Types ¶
type Random ¶ added in v0.4.0
Random extends math/rand/v2 Rand with functions for generating many useful types of data. It also provides a Read function to read random data into a buffer and serve as an io.Reader. Random contains its own pseudo-random source. The same Random instance must not be used concurrently. Create separate Random instances for use in concurrent goroutines.
func New ¶ added in v0.4.0
func New() *Random
New returns a new Random instance that contains its own pseudo-random number source, seeded with a random value.
func NewSeeded ¶ added in v0.4.0
NewSeeded returns a new Random instance that contains its own pseudo-random number source seeded with the specified value. Creating a random source using the same seed value causes the generator to deterministically produce the same sequence of pseudo-random numbers.
func NewSeededRand
deprecated
added in
v0.0.4
func (*Random) AddrInfos ¶ added in v0.4.0
AddrInfos returns a slice AddrInfo with numPeers elements. Each AddrInfo has a unique ID and numAddrs Addresses. The multiaddrs are ipv4 addresses.
func (*Random) Addrs ¶ added in v0.4.0
Addrs returns a slice of n random unique IPv4 addresses with a random port. The string is formatted as a multiaddr: "/ip4/n.n.n.n/tcp/n"
func (*Random) BlocksOfSize ¶ added in v0.4.0
BlocksOfSize generates a slice of blocks of the specified byte size.
func (*Random) Bytes ¶ added in v0.4.0
Bytes returns a byte array of the given size with random values.
func (*Random) DnsAddrInfos ¶ added in v0.4.0
DnsAddrInfos returns a slice AddrInfo with numPeers elements. Each AddrInfo has a unique ID and numAddrs Addresses. The multiaddrs are dns addresses.
func (*Random) DnsAddrs ¶ added in v0.4.0
DnsAddrs returns a slice of n random unique DNS addresses, formmated as a multiaddr: "/dns4/xxxxxxxx.example.com/tcp/n"
func (*Random) DnsMultiaddrs ¶ added in v0.4.0
DnsMultiaddrs returns a slice of n random unique Multiaddrs with dns addresses.
func (*Random) HttpAddrInfos ¶ added in v0.4.0
HttpAddrInfos returns a slice AddrInfo with numPeers elements. Each AddrInfo has a unique ID and numAddrs Addresses. The multiaddrs are ipv4 addresses with http protocol
func (*Random) HttpDnsAddrInfos ¶ added in v0.4.0
HttpDnsAddrInfos returns a slice AddrInfo with numPeers elements. Each AddrInfo has a unique ID and numAddrs Addresses. The multiaddrs are dns addresses with http protocol.
func (*Random) HttpDnsMultiaddrs ¶ added in v0.4.0
HttpDnsMultiaddrs returns a slice of n random unique Multiaddrs with dns addresses and http protocol.
func (*Random) HttpMultiaddrs ¶ added in v0.4.0
HttpMultiaddrs returns a slice of n random unique Multiaddrs with ipv4 addresses and http protocol.
func (*Random) Identity ¶ added in v0.4.0
Identity returns a random unique peer ID, private key, and public key.
func (*Random) Multiaddrs ¶ added in v0.4.0
Multiaddrs returns a slice of n random unique Multiaddrs with ipv4 addresses.
func (*Random) Multihashes ¶ added in v0.4.0
Multihashes returns a slice of n random unique Multihashes.
func (*Random) Name ¶ added in v0.4.0
Name returns a string of n random lower-alphanumeric characters.
func (*Random) NameSize ¶ added in v0.4.0
NameSize returns a string of random lower-alphanumeric characters, having a random size of at least minSize and at most maxSize.
type Sequence ¶ added in v0.0.3
type Sequence struct {
// contains filtered or unexported fields
}
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 NewSequence ¶ added in v0.4.0
func NewSequence() *Sequence
NewSequence creates a new Sequence that starts at a random number.
func NewSequenceAt ¶ added in v0.4.0
NewSequenceAt creates a new Sequence that starts at a the specified number.