rand

package
v1.3.1 Latest Latest
Warning

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

Go to latest
Published: May 11, 2022 License: MPL-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package rand contains randomization functions for use in unit/regression/integration tests or anywhere where randomized data is needed.

Index

Constants

View Source
const (
	Lower      = "abcdefghijklmnopqrstuvwxyz"
	Upper      = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
	Digit      = "0123456789"
	Whitespace = "\t\r\n "
	Special    = "`~!@#$%^&*()-_=+[]{}\\|:;'\"/?,.<>"
)

Constants for commonly used alphabets to provide to String()

View Source
const (
	// Class A network mask: 255.0.0.0 => /8
	IPv4ClassAMask uint32 = 0xFF000000
	// Class B network mask: 255.255.0.0 => /16
	IPv4ClassBMask uint32 = 0xFFFF0000
	// CLass C network mask: 255.255.255.0 => /24
	IPv4ClassCMask uint32 = 0xFFFFFF00
	// Private class B network mask: 255.240.0.0 => /12
	IPv4PrivateClassBMask uint32 = 0xFFF00000
	// Private Class C network mask: 255.255.0.0 => /16
	IPv4PrivateClassCMask uint32 = 0xFFFF0000
)

IPv4 network mask constants

View Source
const (
	// Class A IP address start: 1.0.0.0
	IPv4ClassAStart uint32 = 0x01000000
	// Class B IP address start: 128.0.0.0
	IPv4ClassBStart uint32 = 0x80000000
	// Class C IP address start: 192.0.0.0
	IPv4ClassCStart uint32 = 0xC0000000
	// Class D IP address start: 224.0.0.0
	IPv4ClassDStart uint32 = 0xE0000000
	// Class E IP address start: 240.0.0.0
	IPv4ClassEStart uint32 = 0xF0000000
	// Class A private IP address start: 10.0.0.0
	IPv4PrivateClassAStart uint32 = 0x0A000000
	// Class B private IP address start: 172.16.0.0
	IPv4PrivateClassBStart uint32 = 0xAC100000
	// Class C private IP address start: 192.168.0.0
	IPv4PrivateClassCStart uint32 = 0xC0A80000
)

IPv4 network host starting address constants

Variables

This section is empty.

Functions

func IPv4

func IPv4(startingIP uint32, mask uint32) uint32

IPv4 generates a random IPv4 address beginning with the starting IP address and going up to the broadcast address for that network (inclusive). The ending IP address is determined based on the network mask.

func IPv4Str

func IPv4Str(startingIP uint32, mask uint32) string

IPv4 generates a random IPv4 address and returns the IP address as a string in dotted quad notation. Inputs function similarly to IPv4().

func IntArrayUnique

func IntArrayUnique(n int) []int

IntArrayUnique creates an array of size n filled with randomly generated integers. Each entry in the array will be unique. It panics if the length is negative.

func MACAddr48

func MACAddr48() uint64

MACAddr48 generates a random 48 bit MAC address

func MACAddr48Str

func MACAddr48Str(sep string) string

MACAddr48Str generates a random 48 bit MAC address as a string, using the desired separator between octets.

func MACAddr64

func MACAddr64() uint64

MACAddr64 generates a random 64 bit MAC address

func MACAddr64Str

func MACAddr64Str(sep string) string

MACAddr64Str generates a random 64 bit MAC address as a string, using the desired separator between octets.

func String

func String(n int, alphabet string) string

String creates a random string of n characters with the supplied alphabet. It panics if the alphabet is the empty string, or the length is negative.

func Time

func Time() time.Time

Time generates a random time.Time between 1970-01-00 and 2070-01-00, inclusive.

Types

This section is empty.

Jump to

Keyboard shortcuts

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