random

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Feb 8, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package random provides functions for generating random data

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateFile

func CreateFile(path string, size int64) error

Create a file and fill it with random bytes. NOTE: This will override any existing file. path The path of the file to be created. size The number of random bytes to write to the file.

func CreateFiles

func CreateFiles(dir string,
	minFiles int, maxFiles int,
	minSize uint64, maxSize uint64,
	maxTotalSize uint64) (uint64, error)

Generate random files inside the specified directory Files will be created using data copied from the crypto random generator. dir: is the parent directory minFile: minimum number of files to create maxFile: maximum number of files to create minSize: the minimum size in bytes of a file. maxSize: the maximum size in bytes of a file. maxTotalSize: the maximum number of bytes to be used for all files being created. Return the total number of bytes written.

func CreateTempFile

func CreateTempFile(dir, pattern string, size int64) (string, error)

Create a temporary file and fill it with random bytes. NOTE: This will override any existing file. See os.CreateTemp for details on dir and pattern. size The number of random bytes to write to the file. Returns the path to the file that was created.

func Int

func Int(min int, max int) int

Int returns a random integer between the minimum and maximum.

func Path

func Path(base string, minDirs int, maxDirs int, minNameLen int, maxNameLen int) string

Generate a path consisting of random depth (subdirectories) between min and max minDirs, maxDirs: random range between the minimum and maximum amount of subdirectories to create minNameLen, maxNameLen: random range of length of characters used to generate each random subdirectory's name. The function will always return the base + range(min, max) paths.

func Paths

func Paths(base string, count int, min int, max int, minNameLen int, maxNameLen int) []string

Generate a slice of random paths count: is the number of random paths to create and return

func SecureBytes

func SecureBytes(b []byte) error

Read len(b) bytes into b from the secure random number generator.

func SecureUint32

func SecureUint32() (uint32, error)

Read 4 bytes from the secure random number generator and convert it to an uint32.

func SecureUint64

func SecureUint64() (uint64, error)

Read 8 bytes from the secure random number generator and convert it to an uint64.

func String

func String(n int) string

String produces a string of length n that contains random characters. Characters are chosen from the following set: abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ.

Types

This section is empty.

Jump to

Keyboard shortcuts

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