Documentation
¶
Overview ¶
Package randutil provides cryptographically secure random number generation and related utilities organized into focused sub-packages:
- core: Basic random number generation primitives and entropy source management
- numeric: Random number generation for various numeric types and booleans
- randstring: Random string generation and token creation
- email: Random email address generation with customizable options
- collection: Random sampling, shuffling, and weighted selection for slices
- randtime: Random datetime generation functions
- uuid: UUID generation
All functions use crypto/rand by default for cryptographically secure randomness.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var Collection = collection.Default
Collection provides access to the default collection generator.
var Core = core.New(nil)
Core provides access to the default core generator.
var Email = email.Default
Email provides access to the default email generator.
var String = randstring.Default
String provides access to the default string generator.
var Time = randtime.Default
Time provides access to the default time generator.
var UUID = uuid.Default
UUID provides access to the default UUID generator.
Functions ¶
This section is empty.
Types ¶
type Rand ¶
type Rand struct {
// Core provides basic random number generation primitives.
Core *core.Generator
// String provides random string and token generation.
String *randstring.Generator
// UUID provides UUID v4 and v7 generation.
UUID *uuid.Generator
// Collection provides slice operations like shuffle and sampling.
Collection *collection.Generator
// Time provides random datetime generation.
Time *randtime.Generator
// Email provides random email address generation.
Email *email.Generator
}
Rand provides access to all default generators from the subpackages, bound to a single entropy source. This eliminates the need to duplicate all the methods from each subpackage.
func Default ¶
func Default() Rand
Default returns a Rand using the current secure source (crypto/rand by default).
Returns:
- Rand: A new Rand using the current secure source.
func New ¶
New returns a Rand with all generators bound to src. Pass nil to use crypto/rand via the package default.
Parameters:
- src: The entropy source to use.
Returns:
- Rand: A new Rand with all generators bound to src.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package collection provides random sampling, shuffling, and weighted selection functions for slices and collections.
|
Package collection provides random sampling, shuffling, and weighted selection functions for slices and collections. |
|
Package core provides basic random number generation primitives and entropy source management for the randutil package.
|
Package core provides basic random number generation primitives and entropy source management for the randutil package. |
|
internal
|
|
|
Package numeric provides random number generation functions for various numeric types and boolean values.
|
Package numeric provides random number generation functions for various numeric types and boolean values. |
|
Package randstring provides random string generation and token helpers.
|
Package randstring provides random string generation and token helpers. |
|
Package randtime provides random datetime generation functions.
|
Package randtime provides random datetime generation functions. |
|
Package uuid provides RFC 4122 v4 (random) and RFC 9562 v7 (time-ordered) UUID helpers built on randutil.
|
Package uuid provides RFC 4122 v4 (random) and RFC 9562 v7 (time-ordered) UUID helpers built on randutil. |