Documentation
¶
Index ¶
- Variables
- func ConvertTo(value any, t reflect.Type) (any, error)
- func NewConcurrentSource(source rand.Source) rand.Source
- func Random(t reflect.Type, generators ...RandomGenerator) (any, error)
- func RandomFor[T any](generators ...RandomGenerator) (T, error)
- func RandomOfMap[Map ~map[K]V, K comparable, V any](m Map) K
- func RandomOfSlice[Slice ~[]V, V any](s Slice) V
- type ConcurrentSource
- type RandomGenerator
Constants ¶
This section is empty.
Variables ¶
View Source
var RandomDuration = NewStrictRandomGenerator[time.Duration](func() (any, error) { duration := 24 * time.Hour randomNanos := random.Int64N(duration.Nanoseconds()) value := time.Duration(randomNanos) * time.Nanosecond return value, nil })
View Source
var RandomRegexp = NewRandomGenerator[*regexp.Regexp](func() (any, error) { txt := autoname.Generate("-") return regexp.Compile(txt) })
View Source
var RandomTime = NewRandomGenerator[time.Time](func() (any, error) { start := time.Date(2020, time.January, 1, 0, 0, 0, 0, time.UTC) end := time.Date(2025, time.December, 31, 23, 59, 59, 0, time.UTC) duration := end.Sub(start) randomNanos := random.Int64N(duration.Nanoseconds()) randomDuration := time.Duration(randomNanos) * time.Nanosecond value := start.Add(randomDuration) return value, nil })
Functions ¶
func RandomFor ¶
func RandomFor[T any](generators ...RandomGenerator) (T, error)
func RandomOfMap ¶
func RandomOfMap[Map ~map[K]V, K comparable, V any](m Map) K
func RandomOfSlice ¶
func RandomOfSlice[Slice ~[]V, V any](s Slice) V
Types ¶
type ConcurrentSource ¶ added in v1.0.1
func (*ConcurrentSource) Uint64 ¶ added in v1.0.1
func (c *ConcurrentSource) Uint64() uint64
type RandomGenerator ¶
func NewRandomGenerator ¶
func NewRandomGenerator[T any](random func() (any, error)) RandomGenerator
func NewStrictRandomGenerator ¶
func NewStrictRandomGenerator[T any](random func() (any, error)) RandomGenerator
Directories
¶
| Path | Synopsis |
|---|---|
|
examples
|
|
|
Basic
command
|
|
|
CustomGenerator
command
|
|
|
StringerwithHook
command
|
|
|
pkg
|
|
Click to show internal directories.
Click to hide internal directories.