Documentation
¶
Overview ¶
Package gengo provides a simple and practical way to generate random data structures. It offers a zero-dependency API for generating random values of standard Go types including integers, floats, complex numbers, strings, booleans, dates, and words.
The package-level functions draw from the global math/rand/v2 source and are safe for concurrent use. For reproducible output, use a seeded Generator created with New or NewSource.
gengo is not cryptographically secure: it is built on math/rand/v2, whose output is predictable. Do not use it for passwords, tokens, keys, or any other secret; use crypto/rand instead.
Index ¶
- Constants
- func AdjectivePT() string
- func AdjectivePTOf(g Gender, n Number, d Degree, l LengthTypeWords) string
- func AdverbPT() string
- func AdverbPTByLengthType(l LengthTypeWords) string
- func ArticlePT() string
- func Bool() bool
- func Byte() byte
- func Complex64() complex64
- func Complex64Between(minReal, maxReal, minImag, maxImag float32) complex64
- func Complex128() complex128
- func Complex128Between(minReal, maxReal, minImag, maxImag float64) complex128
- func ConjunctionPT() string
- func Date() time.Time
- func DateBetween(start, end time.Time) time.Time
- func Float32() float32
- func Float32Between(min, max float32) float32
- func Float64() float64
- func Float64Between(min, max float64) float64
- func Int() int
- func Int8() int8
- func Int8Between(min, max int8) int8
- func Int16() int16
- func Int16Between(min, max int16) int16
- func Int32() int32
- func Int32Between(min, max int32) int32
- func Int64() int64
- func Int64Between(min, max int64) int64
- func IntBetween(min, max int) int
- func InterjectionPT() string
- func NounPT() string
- func NounPTOf(g Gender, n Number, l LengthTypeWords) string
- func NumeralPT() string
- func PrepositionPT() string
- func PronounPT() string
- func String(length uint32, sourceChars string) string
- func StringAllChars(length uint32) string
- func StringAlphabetic(length uint32) string
- func StringAlphabeticLowercase(length uint32) string
- func StringAlphabeticUppercase(length uint32) string
- func StringAlphanumeric(length uint32) string
- func StringBetween(min, max uint32, sourceChars string) string
- func StringHexadecimal(length uint32) string
- func StringNumeric(length uint32) string
- func StringSymbols(length uint32) string
- func Uint8() uint8
- func Uint8Between(min, max uint8) uint8
- func Uint16() uint16
- func Uint16Between(min, max uint16) uint16
- func Uint32() uint32
- func Uint32Between(min, max uint32) uint32
- func Uint64() uint64
- func Uint64Between(min, max uint64) uint64
- func UnixDate() time.Time
- func VerbPT() string
- func VerbPTOf(m Mood, t Tense, p Person, n Number, l LengthTypeWords) string
- func Word() string
- func WordByLengthType(l LengthTypeWords) (word string)
- func WordPT() string
- func WordPTByLengthType(l LengthTypeWords) string
- func Words(length int) (result []string)
- func WordsPT(n int) []string
- type Degree
- type Gender
- type Generator
- func (g *Generator) AdjectivePT() string
- func (g *Generator) AdjectivePTOf(gender Gender, n Number, d Degree, l LengthTypeWords) string
- func (g *Generator) AdverbPT() string
- func (g *Generator) AdverbPTByLengthType(l LengthTypeWords) string
- func (g *Generator) ArticlePT() string
- func (g *Generator) Bool() bool
- func (g *Generator) Byte() byte
- func (g *Generator) Complex64() complex64
- func (g *Generator) Complex64Between(minReal, maxReal, minImag, maxImag float32) complex64
- func (g *Generator) Complex128() complex128
- func (g *Generator) Complex128Between(minReal, maxReal, minImag, maxImag float64) complex128
- func (g *Generator) ConjunctionPT() string
- func (g *Generator) Date() time.Time
- func (g *Generator) DateBetween(start, end time.Time) time.Time
- func (g *Generator) Float32() float32
- func (g *Generator) Float32Between(min, max float32) float32
- func (g *Generator) Float64() float64
- func (g *Generator) Float64Between(min, max float64) float64
- func (g *Generator) Int() int
- func (g *Generator) Int8() int8
- func (g *Generator) Int8Between(min, max int8) int8
- func (g *Generator) Int16() int16
- func (g *Generator) Int16Between(min, max int16) int16
- func (g *Generator) Int32() int32
- func (g *Generator) Int32Between(min, max int32) int32
- func (g *Generator) Int64() int64
- func (g *Generator) Int64Between(min, max int64) int64
- func (g *Generator) IntBetween(min, max int) int
- func (g *Generator) InterjectionPT() string
- func (g *Generator) NounPT() string
- func (g *Generator) NounPTOf(gender Gender, n Number, l LengthTypeWords) string
- func (g *Generator) NumeralPT() string
- func (g *Generator) PrepositionPT() string
- func (g *Generator) PronounPT() string
- func (g *Generator) String(length uint32, sourceChars string) string
- func (g *Generator) StringAllChars(length uint32) string
- func (g *Generator) StringAlphabetic(length uint32) string
- func (g *Generator) StringAlphabeticLowercase(length uint32) string
- func (g *Generator) StringAlphabeticUppercase(length uint32) string
- func (g *Generator) StringAlphanumeric(length uint32) string
- func (g *Generator) StringBetween(min, max uint32, sourceChars string) string
- func (g *Generator) StringHexadecimal(length uint32) string
- func (g *Generator) StringNumeric(length uint32) string
- func (g *Generator) StringSymbols(length uint32) string
- func (g *Generator) Uint8() uint8
- func (g *Generator) Uint8Between(min, max uint8) uint8
- func (g *Generator) Uint16() uint16
- func (g *Generator) Uint16Between(min, max uint16) uint16
- func (g *Generator) Uint32() uint32
- func (g *Generator) Uint32Between(min, max uint32) uint32
- func (g *Generator) Uint64() uint64
- func (g *Generator) Uint64Between(min, max uint64) uint64
- func (g *Generator) UnixDate() time.Time
- func (g *Generator) VerbPT() string
- func (g *Generator) VerbPTOf(m Mood, t Tense, p Person, n Number, l LengthTypeWords) string
- func (g *Generator) Word() string
- func (g *Generator) WordByLengthType(l LengthTypeWords) (word string)
- func (g *Generator) WordPT() string
- func (g *Generator) WordPTByLengthType(l LengthTypeWords) string
- func (g *Generator) Words(length int) []string
- func (g *Generator) WordsPT(n int) []string
- type LengthTypeWords
- type Mood
- type Number
- type Person
- type Tense
Examples ¶
Constants ¶
const ( AllChars string = `abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%&*()-_=+[]{}<>?/|\^~` Alphanumeric string = `abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789` Alphabetic string = `abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ` AlphabeticUppercase string = `ABCDEFGHIJKLMNOPQRSTUVWXYZ` AlphabeticLowercase string = `abcdefghijklmnopqrstuvwxyz` Numeric string = `0123456789` Hexadecimal string = `0123456789ABCDEF` Symbols string = `!@#$%&*()-_=+[]{}<>?/|\^~` MaxStringLength uint32 = 1024 * 1024 // 1MB maximum string length )
Character sets available for string generation.
const WordLengthRatio = `11111111111112222222222222222222222222233333333333`
WordLengthRatio is the sampling table that defines the natural length distribution used by Words. Each digit selects a length category ('1' small, '2' medium, '3' big); the proportions (13/26/11 of 50) yield roughly 26% small, 52% medium, and 22% big words.
Variables ¶
This section is empty.
Functions ¶
func AdjectivePT ¶ added in v0.2.0
func AdjectivePT() string
AdjectivePT returns a random European-Portuguese (pt-PT) pseudo-adjective with a random gender, number, degree and length. It is exact sugar for AdjectivePTOf(AnyGender, AnyNumber, AnyDegree, AnyLengthWord). The result is a lowercase, valid-UTF-8 word that follows pt-PT adjective morphology and graphic accentuation; it is a plausible invented word, not guaranteed to be a real dictionary entry.
AdjectivePT draws from the global, automatically seeded math/rand/v2 source and is safe for concurrent use by multiple goroutines. For reproducible output, use a seeded Generator (New or NewSource) and its AdjectivePT method.
func AdjectivePTOf ¶ added in v0.2.0
func AdjectivePTOf(g Gender, n Number, d Degree, l LengthTypeWords) string
AdjectivePTOf returns a random pt-PT pseudo-adjective inflected for gender g, number n and degree d, within length category l. Each option's Any zero value (AnyGender, AnyNumber, AnyDegree, AnyLengthWord) selects a random valid value. A gender-inflecting ending realizes the requested gender directly; a gender-invariable ending serves either request with one form. Degree Positive yields the base adjective; Superlative yields the synthetic absolute superlative -íssimo/-íssima, inflected for gender and number. When l cannot hold any adjective of the chosen ending and degree, l is normalized upward to the smallest category that can (length is never normalized downward); in particular a Superlative never fits SmallLengthWord and normalizes up. The result is always lowercase and valid UTF-8; the function never returns an error and never panics.
AdjectivePTOf draws from the global, automatically seeded math/rand/v2 source and is safe for concurrent use by multiple goroutines.
Example ¶
ExampleAdjectivePTOf generates a pt-PT pseudo-adjective in the synthetic absolute superlative degree. The masculine singular superlative always ends in the -íssimo suffix.
package main
import (
"fmt"
"github.com/FlavioCFOliveira/gengo"
)
func main() {
g := gengo.New(7)
fmt.Println(g.AdjectivePTOf(gengo.Masculine, gengo.Singular, gengo.Superlative, gengo.AnyLengthWord))
}
Output: racantíssimo
func AdverbPT ¶ added in v0.2.0
func AdverbPT() string
AdverbPT returns a random European-Portuguese (pt-PT) pseudo-adverb: a productive -mente adverb of random length. It is exact sugar for AdverbPTByLengthType(AnyLengthWord). The result is a lowercase, valid-UTF-8 word formed from the feminine singular of a generated adjective plus -mente; it is invariable and carries no graphic accent. It is a plausible invented word, not guaranteed to be a real dictionary entry.
AdverbPT draws from the global, automatically seeded math/rand/v2 source and is safe for concurrent use by multiple goroutines. For reproducible output, use a seeded Generator (New or NewSource) and its AdverbPT method.
Example ¶
ExampleAdverbPT generates a pt-PT pseudo-adverb. Every generated adverb is a productive -mente form and is invariable.
package main
import (
"fmt"
"github.com/FlavioCFOliveira/gengo"
)
func main() {
g := gengo.New(6)
fmt.Println(g.AdverbPT())
}
Output: dilrantemente
func AdverbPTByLengthType ¶ added in v0.2.0
func AdverbPTByLengthType(l LengthTypeWords) string
AdverbPTByLengthType returns a random pt-PT productive -mente adverb within length category l. AnyLengthWord (the zero value) selects a random valid length. A -mente adverb is invariable — it does not inflect for gender, number, or degree — so length is its only option. When l cannot hold any -mente adverb (its shortest form exceeds the category ceiling), l is normalized upward to the smallest category that can (length is never normalized downward); in particular an adverb never fits SmallLengthWord and normalizes up. The result is always lowercase and valid UTF-8; the function never returns an error and never panics.
AdverbPTByLengthType draws from the global, automatically seeded math/rand/v2 source and is safe for concurrent use by multiple goroutines.
func ArticlePT ¶ added in v0.2.0
func ArticlePT() string
ArticlePT returns a real European-Portuguese (pt-PT) article, selected uniformly at random from the curated, exhaustive list of single-word articles (definite, indefinite, and single-word preposition+article contractions such as "do", "no", "pelo", "à"). The result is a real, lowercase, correctly accented pt-PT word, never invented; the length concept does not apply to closed classes, so ArticlePT takes no length option.
ArticlePT draws from the global, automatically seeded math/rand/v2 source and is safe for concurrent use by multiple goroutines. For reproducible output, use a seeded Generator (New or NewSource) and its ArticlePT method.
func Complex64 ¶
func Complex64() complex64
Complex64 returns a random complex64 with real and imaginary parts in [0, 1).
func Complex64Between ¶ added in v0.0.8
Complex64Between returns a random complex64 with real part in [minReal, maxReal] and imaginary part in [minImag, maxImag].
func Complex128 ¶
func Complex128() complex128
Complex128 returns a random complex128 with real and imaginary parts in [0, 1).
func Complex128Between ¶ added in v0.0.8
func Complex128Between(minReal, maxReal, minImag, maxImag float64) complex128
Complex128Between returns a random complex128 with real part in [minReal, maxReal] and imaginary part in [minImag, maxImag].
func ConjunctionPT ¶ added in v0.2.0
func ConjunctionPT() string
ConjunctionPT returns a real pt-PT conjunction, selected uniformly at random from the curated, exhaustive list of single-word coordinating and subordinating conjunctions (for example "e", "mas", "porém", "porque", "embora"). The result is a real, lowercase, correctly accented pt-PT word; conjunctional locutions are excluded and the length concept does not apply, so ConjunctionPT takes no length option.
ConjunctionPT draws from the global, automatically seeded math/rand/v2 source and is safe for concurrent use by multiple goroutines. For reproducible output, use a seeded Generator (New or NewSource) and its ConjunctionPT method.
func Date ¶
Date returns a random time.Time uniformly distributed across the full Gregorian calendar range (year 1–9999).
func DateBetween ¶
DateBetween returns a random time.Time in [start, end]. Arguments are swapped if start is after end.
DateBetween operates at whole-second granularity: the bounds' sub-second components are ignored, and the returned time is in UTC with a zero sub-second component. As a special case, when start and end fall within the same second, start is returned unchanged, preserving its sub-second component and location.
func Float32Between ¶ added in v0.0.8
Float32Between returns a random float32 in [min, max]. Arguments are swapped if min > max.
func Float64Between ¶ added in v0.0.8
Float64Between returns a random float64 in [min, max]. Arguments are swapped if min > max.
func Int ¶
func Int() int
Int returns a random int across the full [math.MinInt, math.MaxInt] range.
func Int8 ¶
func Int8() int8
Int8 returns a random int8 across the full [math.MinInt8, math.MaxInt8] range.
func Int8Between ¶
Int8Between returns a random int8 in [min, max]. Arguments are swapped if min > max.
func Int16 ¶
func Int16() int16
Int16 returns a random int16 across the full [math.MinInt16, math.MaxInt16] range.
func Int16Between ¶
Int16Between returns a random int16 in [min, max]. Arguments are swapped if min > max.
func Int32 ¶ added in v0.0.13
func Int32() int32
Int32 returns a random int32 across the full [math.MinInt32, math.MaxInt32] range.
func Int32Between ¶ added in v0.0.13
Int32Between returns a random int32 in [min, max]. Arguments are swapped if min > max.
func Int64 ¶
func Int64() int64
Int64 returns a random int64 across the full [math.MinInt64, math.MaxInt64] range.
func Int64Between ¶
Int64Between returns a random int64 in [min, max]. Arguments are swapped if min > max.
func IntBetween ¶
IntBetween returns a random int in [min, max]. Arguments are swapped if min > max.
func InterjectionPT ¶ added in v0.2.0
func InterjectionPT() string
InterjectionPT returns a real pt-PT interjection, selected uniformly at random from the curated, representative list of single-word interjections (for example "ah", "olá", "oxalá", "caramba", "psiu", "arre"). The result is a real, lowercase, correctly accented pt-PT word; interjectional locutions are excluded and the length concept does not apply, so InterjectionPT takes no length option.
InterjectionPT draws from the global, automatically seeded math/rand/v2 source and is safe for concurrent use by multiple goroutines. For reproducible output, use a seeded Generator (New or NewSource) and its InterjectionPT method.
func NounPT ¶ added in v0.2.0
func NounPT() string
NounPT returns a random European-Portuguese (pt-PT) pseudo-noun with a random gender, number and length. It is exact sugar for NounPTOf(AnyGender, AnyNumber, AnyLengthWord). The result is a lowercase, valid-UTF-8 word that follows pt-PT noun morphology and graphic accentuation; it is a plausible invented word, not guaranteed to be a real dictionary entry.
NounPT draws from the global, automatically seeded math/rand/v2 source and is safe for concurrent use by multiple goroutines. For reproducible output, use a seeded Generator (New or NewSource) and its NounPT method.
func NounPTOf ¶ added in v0.2.0
func NounPTOf(g Gender, n Number, l LengthTypeWords) string
NounPTOf returns a random pt-PT pseudo-noun inflected for gender g and number n, within length category l. Each option's Any zero value (AnyGender, AnyNumber, AnyLengthWord) selects a random valid value. A gender-inflecting ending realizes the requested gender directly; a gender-fixed or common-gender ending is chosen only when it is compatible with the request. When l cannot hold any noun of the chosen ending, l is normalized upward to the smallest category that can (length is never normalized downward). The result is always lowercase and valid UTF-8; the function never returns an error and never panics.
NounPTOf draws from the global, automatically seeded math/rand/v2 source and is safe for concurrent use by multiple goroutines.
Example ¶
ExampleNounPTOf generates a pt-PT pseudo-noun inflected for a specific gender, number, and length category. Here the request is a feminine plural noun in the medium length category (5 to 8 characters).
package main
import (
"fmt"
"github.com/FlavioCFOliveira/gengo"
)
func main() {
g := gengo.New(1)
fmt.Println(g.NounPTOf(gengo.Feminine, gengo.Plural, gengo.MediumLengthWords))
}
Output: gruistas
func NumeralPT ¶ added in v0.2.0
func NumeralPT() string
NumeralPT returns a real pt-PT numeral, selected uniformly at random from the curated list of single-word numerals across the four subtypes: cardinal, ordinal, multiplicative, and fractional (for example "três", "cem", "milhão", "primeiro", "décima", "vigésimo", "quíntuplo", "meio", "terço"). The result is a real, lowercase, correctly accented pt-PT word in European-Portuguese spelling (for example "catorze", "dezasseis", "bilião", never the Brazilian "quatorze", "dezesseis", "bilhão"); multi-word compound numbers (for example "vinte e um") are excluded and the length concept does not apply, so NumeralPT takes no length option.
NumeralPT draws from the global, automatically seeded math/rand/v2 source and is safe for concurrent use by multiple goroutines. For reproducible output, use a seeded Generator (New or NewSource) and its NumeralPT method.
func PrepositionPT ¶ added in v0.2.0
func PrepositionPT() string
PrepositionPT returns a real pt-PT preposition, selected uniformly at random from the curated, exhaustive list of essential (simple) prepositions (for example "a", "de", "para", "após", "sobre"). The result is a real, lowercase, correctly accented pt-PT word; prepositional locutions are excluded and the length concept does not apply, so PrepositionPT takes no length option.
PrepositionPT draws from the global, automatically seeded math/rand/v2 source and is safe for concurrent use by multiple goroutines. For reproducible output, use a seeded Generator (New or NewSource) and its PrepositionPT method.
Example ¶
ExamplePrepositionPT selects a real pt-PT preposition. Closed-class selectors return genuine, curated words rather than generated pseudo-words.
package main
import (
"fmt"
"github.com/FlavioCFOliveira/gengo"
)
func main() {
g := gengo.New(5)
fmt.Println(g.PrepositionPT())
}
Output: perante
func PronounPT ¶ added in v0.2.0
func PronounPT() string
PronounPT returns a real pt-PT pronoun, selected uniformly at random from the curated, exhaustive list that spans every subtype: personal (subject, atonic oblique, and tonic oblique, including the archaic-but-real "vós" forms such as "vós", "convosco", and "vosso"), possessive, demonstrative, indefinite, relative, and interrogative (for example "eu", "lhe", "consigo", "minhas", "aquilo", "nenhuma", "cujo", "quem"). The result is a real, lowercase, correctly accented pt-PT word; the length concept does not apply to closed classes, so PronounPT takes no length option.
PronounPT draws from the global, automatically seeded math/rand/v2 source and is safe for concurrent use by multiple goroutines. For reproducible output, use a seeded Generator (New or NewSource) and its PronounPT method.
func String ¶
String generates a length-byte string by sampling bytes from sourceChars.
It is byte-oriented: length counts bytes (not runes), characters are picked by byte index, and sourceChars is expected to hold only single-byte (ASCII) characters — every predefined character set in this package qualifies. Passing a multibyte charset (emoji, accented letters, CJK, and so on) samples individual UTF-8 bytes and therefore yields invalid UTF-8, so use an ASCII charset instead. length is capped at MaxStringLength bytes.
Example ¶
HexColor := String(8, "0123456789ABCDEF") fmt.Println(HexColor)
func StringAllChars ¶
StringAllChars returns a string with a given length containing all the predefined alphabetic, alphanumeric and symbols characters.
func StringAlphabetic ¶
StringAlphabetic returns a string with a given length containing only alphabetic characters.
func StringAlphabeticLowercase ¶
StringAlphabeticLowercase returns a string with a given length containing only alphabetic characters in lower case only.
func StringAlphabeticUppercase ¶
StringAlphabeticUppercase returns a string with a given length containing only alphabetic characters in upper case only.
func StringAlphanumeric ¶
StringAlphanumeric returns a string with a given length containing only alphanumeric characters.
func StringBetween ¶ added in v0.0.10
StringBetween generates a string with a variable length using only characters of a given source.
func StringHexadecimal ¶
StringHexadecimal returns a string with a given length containing only hexadecimal characters.
func StringNumeric ¶
StringNumeric returns a string with a given length containing only numeric characters.
func StringSymbols ¶
StringSymbols returns a string with a given length containing only symbols characters.
func Uint8 ¶ added in v0.1.0
func Uint8() uint8
Uint8 returns a random uint8 across the full [0, math.MaxUint8] range.
func Uint8Between ¶ added in v0.1.0
Uint8Between returns a random uint8 in [min, max]. Arguments are swapped if min > max.
func Uint16 ¶ added in v0.1.0
func Uint16() uint16
Uint16 returns a random uint16 across the full [0, math.MaxUint16] range.
func Uint16Between ¶ added in v0.1.0
Uint16Between returns a random uint16 in [min, max]. Arguments are swapped if min > max.
func Uint32 ¶ added in v0.1.0
func Uint32() uint32
Uint32 returns a random uint32 across the full [0, math.MaxUint32] range.
func Uint32Between ¶ added in v0.1.0
Uint32Between returns a random uint32 in [min, max]. Arguments are swapped if min > max.
func Uint64 ¶ added in v0.1.0
func Uint64() uint64
Uint64 returns a random uint64 across the full [0, math.MaxUint64] range.
func Uint64Between ¶ added in v0.1.0
Uint64Between returns a random uint64 in [min, max]. Arguments are swapped if min > max.
func UnixDate ¶ added in v0.0.13
UnixDate returns a random time.Time uniformly distributed within the Unix epoch range (1970–2038).
func VerbPT ¶ added in v0.2.0
func VerbPT() string
VerbPT returns a random European-Portuguese (pt-PT) pseudo-verb form in a random paradigm slot: a random mood, tense, person, number and length. It is exact sugar for VerbPTOf(AnyMood, AnyTense, AnyPerson, AnyNumber, AnyLengthWord). The result is a lowercase, valid-UTF-8 word that follows the regular pt-PT verb conjugation and graphic accentuation; it is a plausible invented word, not guaranteed to be a real dictionary entry.
VerbPT draws from the global, automatically seeded math/rand/v2 source and is safe for concurrent use by multiple goroutines. For reproducible output, use a seeded Generator (New or NewSource) and its VerbPT method.
func VerbPTOf ¶ added in v0.2.0
VerbPTOf returns a random pt-PT pseudo-verb produced in the paradigm slot addressed by mood m, tense t, person p and number n, within length category l. Each option's Any zero value (AnyMood, AnyTense, AnyPerson, AnyNumber, AnyLengthWord) selects a random valid value for the resolved mood.
The mood governs which of the other options apply. The finite indicative and subjunctive use the tense, person and number; the imperative uses the person and number (it has no tense selection); the infinitive uses the person and number (to choose between the impersonal and the inflected personal infinitive); the gerund and the participle are invariable (person, number and tense are ignored).
Grammatically impossible combinations never error or panic; each normalizes to the nearest valid form, per the deterministic matrix of specification/wordspt-open-classes.md: a second person plural request becomes third person plural (N1); a first person singular imperative becomes first person plural (N2); a subjunctive Preterite becomes Imperfect and a subjunctive Conditional becomes Future (N3); a tense on a non-finite or imperative mood is ignored (N3); and an unviable length category is normalized upward to the smallest category that can hold the resolved slot (N5), never downward. The result is always lowercase and valid UTF-8.
VerbPTOf draws from the global, automatically seeded math/rand/v2 source and is safe for concurrent use by multiple goroutines.
Example ¶
ExampleVerbPTOf generates a pt-PT pseudo-verb in a specific paradigm slot: the present indicative, first person singular.
package main
import (
"fmt"
"github.com/FlavioCFOliveira/gengo"
)
func main() {
g := gengo.New(3)
fmt.Println(g.VerbPTOf(gengo.Indicative, gengo.Present, gengo.First, gengo.Singular, gengo.AnyLengthWord))
}
Output: onalgro
func Word ¶
func Word() string
Word returns a random lowercase alphabetic word between 2 and 30 characters.
func WordByLengthType ¶
func WordByLengthType(l LengthTypeWords) (word string)
WordByLengthType returns a random lowercase alphabetic word of the given length category.
func WordPT ¶ added in v0.2.0
func WordPT() string
WordPT returns a random European-Portuguese (pt-PT) word of a random class, following the natural class distribution described in this package. It is exact sugar for WordPTByLengthType(AnyLengthWord). The result is a lowercase, valid-UTF-8 pt-PT word: a generated pseudo-word for the open classes (noun, adjective, verb, adverb) or a real curated word for the closed classes (article, pronoun, numeral, preposition, conjunction, interjection).
WordPT draws from the global, automatically seeded math/rand/v2 source and is safe for concurrent use by multiple goroutines. For reproducible output, use a seeded Generator (New or NewSource) and its WordPT method.
func WordPTByLengthType ¶ added in v0.2.0
func WordPTByLengthType(l LengthTypeWords) string
WordPTByLengthType returns a random pt-PT word of a random class, as WordPT, with the length category l applied to the open classes. A concrete category (SmallLengthWord, MediumLengthWords or BigLengthWords) constrains a generated open-class word to that character window, normalizing upward when the category cannot hold the chosen class (length is never normalized downward). AnyLengthWord (the zero value) selects the natural length distribution. The closed classes ignore l entirely, because their output is a fixed real word. The result is always lowercase and valid UTF-8; the function never returns an error and never panics.
WordPTByLengthType draws from the global, automatically seeded math/rand/v2 source and is safe for concurrent use by multiple goroutines.
func Words ¶
Words returns a slice of length random words with a natural distribution across length categories. Returns an empty slice when length <= 0.
func WordsPT ¶ added in v0.2.0
WordsPT returns a slice of n random pt-PT words following the natural class distribution, mirroring the semantics of Words. It returns a non-nil, empty slice when n is less than or equal to zero, and a slice of exactly n words otherwise. Each word is drawn independently, exactly as WordPT draws one.
WordsPT draws from the global, automatically seeded math/rand/v2 source and is safe for concurrent use by multiple goroutines. For reproducible output, use a seeded Generator (New or NewSource) and its WordsPT method.
Example ¶
ExampleWordsPT generates a slice of random pt-PT words following the natural distribution across word classes. Open-class words are generated pseudo-words, while closed-class words (such as the numeral "quatro" below) are real words.
package main
import (
"fmt"
"github.com/FlavioCFOliveira/gengo"
)
func main() {
g := gengo.New(6)
fmt.Println(g.WordsPT(5))
}
Output: [quatro escas sesmando murnalmente seblares]
Types ¶
type Degree ¶ added in v0.2.0
type Degree uint8
Degree is the degree option of a generated adjective. Its zero value, AnyDegree, means "choose a valid degree at random". Only the positive and the synthetic absolute superlative (-íssimo) are supported; the comparative and the analytic superlatives are multi-word forms and are out of scope.
type Gender ¶ added in v0.2.0
type Gender uint8
Gender is the grammatical gender option of a generated nominal pt-PT word. Its zero value, AnyGender, means "choose a valid gender at random".
type Generator ¶ added in v0.1.0
type Generator struct {
// contains filtered or unexported fields
}
Generator produces random values from an explicit, seeded source, enabling reproducible output: two generators created with the same seed yield the same sequence of values. Its methods mirror the package-level functions exactly, drawing from the generator's own source instead of the global one.
A Generator is NOT safe for concurrent use by multiple goroutines (it wraps a math/rand/v2 *Rand). Use one Generator per goroutine, or use the package-level functions (which are safe for concurrent use) when reproducibility is not required.
Example ¶
ExampleGenerator shows that two generators created with the same seed produce the same sequence of words, which is what makes seeded output reproducible.
package main
import (
"fmt"
"github.com/FlavioCFOliveira/gengo"
)
func main() {
a := gengo.New(7)
b := gengo.New(7)
fmt.Println(a.WordsPT(3))
fmt.Println(b.WordsPT(3))
}
Output: [a sedoraríamos teichãospores] [a sedoraríamos teichãospores]
func New ¶ added in v0.1.0
New returns a Generator seeded with the given value. The same seed always produces the same sequence of values, which is useful for reproducing a specific run (for example, a failing test case).
func NewSource ¶ added in v0.1.0
NewSource returns a Generator that draws from the given source, allowing any math/rand/v2 Source (for example rand.NewPCG or rand.NewChaCha8) to be used. The source must not be nil.
func (*Generator) AdjectivePT ¶ added in v0.2.0
AdjectivePT is the seeded-generator equivalent of AdjectivePT. A Generator created with the same seed produces the same sequence of adjectives.
func (*Generator) AdjectivePTOf ¶ added in v0.2.0
AdjectivePTOf is the seeded-generator equivalent of AdjectivePTOf. A Generator created with the same seed produces the same sequence of adjectives for the same arguments.
func (*Generator) AdverbPT ¶ added in v0.2.0
AdverbPT is the seeded-generator equivalent of AdverbPT. A Generator created with the same seed produces the same sequence of adverbs.
func (*Generator) AdverbPTByLengthType ¶ added in v0.2.0
func (g *Generator) AdverbPTByLengthType(l LengthTypeWords) string
AdverbPTByLengthType is the seeded-generator equivalent of AdverbPTByLengthType. A Generator created with the same seed produces the same sequence of adverbs for the same length category.
func (*Generator) ArticlePT ¶ added in v0.2.0
ArticlePT is the seeded-generator equivalent of ArticlePT. A Generator created with the same seed produces the same sequence of articles.
func (*Generator) Complex64 ¶ added in v0.1.0
Complex64 is the seeded-generator equivalent of Complex64.
func (*Generator) Complex64Between ¶ added in v0.1.0
Complex64Between is the seeded-generator equivalent of Complex64Between.
func (*Generator) Complex128 ¶ added in v0.1.0
func (g *Generator) Complex128() complex128
Complex128 is the seeded-generator equivalent of Complex128.
func (*Generator) Complex128Between ¶ added in v0.1.0
func (g *Generator) Complex128Between(minReal, maxReal, minImag, maxImag float64) complex128
Complex128Between is the seeded-generator equivalent of Complex128Between.
func (*Generator) ConjunctionPT ¶ added in v0.2.0
ConjunctionPT is the seeded-generator equivalent of ConjunctionPT. A Generator created with the same seed produces the same sequence of conjunctions.
func (*Generator) DateBetween ¶ added in v0.1.0
DateBetween is the seeded-generator equivalent of DateBetween.
func (*Generator) Float32Between ¶ added in v0.1.0
Float32Between is the seeded-generator equivalent of Float32Between.
func (*Generator) Float64Between ¶ added in v0.1.0
Float64Between is the seeded-generator equivalent of Float64Between.
func (*Generator) Int8Between ¶ added in v0.1.0
Int8Between is the seeded-generator equivalent of Int8Between.
func (*Generator) Int16Between ¶ added in v0.1.0
Int16Between is the seeded-generator equivalent of Int16Between.
func (*Generator) Int32Between ¶ added in v0.1.0
Int32Between is the seeded-generator equivalent of Int32Between.
func (*Generator) Int64Between ¶ added in v0.1.0
Int64Between is the seeded-generator equivalent of Int64Between.
func (*Generator) IntBetween ¶ added in v0.1.0
IntBetween is the seeded-generator equivalent of IntBetween.
func (*Generator) InterjectionPT ¶ added in v0.2.0
InterjectionPT is the seeded-generator equivalent of InterjectionPT. A Generator created with the same seed produces the same sequence of interjections.
func (*Generator) NounPT ¶ added in v0.2.0
NounPT is the seeded-generator equivalent of NounPT. A Generator created with the same seed produces the same sequence of nouns.
func (*Generator) NounPTOf ¶ added in v0.2.0
func (g *Generator) NounPTOf(gender Gender, n Number, l LengthTypeWords) string
NounPTOf is the seeded-generator equivalent of NounPTOf. A Generator created with the same seed produces the same sequence of nouns for the same arguments.
func (*Generator) NumeralPT ¶ added in v0.2.0
NumeralPT is the seeded-generator equivalent of NumeralPT. A Generator created with the same seed produces the same sequence of numerals.
func (*Generator) PrepositionPT ¶ added in v0.2.0
PrepositionPT is the seeded-generator equivalent of PrepositionPT. A Generator created with the same seed produces the same sequence of prepositions.
func (*Generator) PronounPT ¶ added in v0.2.0
PronounPT is the seeded-generator equivalent of PronounPT. A Generator created with the same seed produces the same sequence of pronouns.
func (*Generator) StringAllChars ¶ added in v0.1.0
StringAllChars is the seeded-generator equivalent of StringAllChars.
func (*Generator) StringAlphabetic ¶ added in v0.1.0
StringAlphabetic is the seeded-generator equivalent of StringAlphabetic.
func (*Generator) StringAlphabeticLowercase ¶ added in v0.1.0
StringAlphabeticLowercase is the seeded-generator equivalent of StringAlphabeticLowercase.
func (*Generator) StringAlphabeticUppercase ¶ added in v0.1.0
StringAlphabeticUppercase is the seeded-generator equivalent of StringAlphabeticUppercase.
func (*Generator) StringAlphanumeric ¶ added in v0.1.0
StringAlphanumeric is the seeded-generator equivalent of StringAlphanumeric.
func (*Generator) StringBetween ¶ added in v0.1.0
StringBetween is the seeded-generator equivalent of StringBetween.
func (*Generator) StringHexadecimal ¶ added in v0.1.0
StringHexadecimal is the seeded-generator equivalent of StringHexadecimal.
func (*Generator) StringNumeric ¶ added in v0.1.0
StringNumeric is the seeded-generator equivalent of StringNumeric.
func (*Generator) StringSymbols ¶ added in v0.1.0
StringSymbols is the seeded-generator equivalent of StringSymbols.
func (*Generator) Uint8Between ¶ added in v0.1.0
Uint8Between is the seeded-generator equivalent of Uint8Between.
func (*Generator) Uint16Between ¶ added in v0.1.0
Uint16Between is the seeded-generator equivalent of Uint16Between.
func (*Generator) Uint32Between ¶ added in v0.1.0
Uint32Between is the seeded-generator equivalent of Uint32Between.
func (*Generator) Uint64Between ¶ added in v0.1.0
Uint64Between is the seeded-generator equivalent of Uint64Between.
func (*Generator) UnixDate ¶ added in v0.1.0
UnixDate is the seeded-generator equivalent of UnixDate.
func (*Generator) VerbPT ¶ added in v0.2.0
VerbPT is the seeded-generator equivalent of VerbPT. A Generator created with the same seed produces the same sequence of verb forms.
func (*Generator) VerbPTOf ¶ added in v0.2.0
VerbPTOf is the seeded-generator equivalent of VerbPTOf. A Generator created with the same seed produces the same sequence of verb forms for the same arguments.
func (*Generator) WordByLengthType ¶ added in v0.1.0
func (g *Generator) WordByLengthType(l LengthTypeWords) (word string)
WordByLengthType is the seeded-generator equivalent of WordByLengthType.
func (*Generator) WordPT ¶ added in v0.2.0
WordPT is the seeded-generator equivalent of WordPT. A Generator created with the same seed produces the same sequence of words.
func (*Generator) WordPTByLengthType ¶ added in v0.2.0
func (g *Generator) WordPTByLengthType(l LengthTypeWords) string
WordPTByLengthType is the seeded-generator equivalent of WordPTByLengthType. A Generator created with the same seed produces the same sequence of words for the same length category.
type LengthTypeWords ¶
type LengthTypeWords uint8
LengthTypeWords classifies a word by its character length category.
const AnyLengthWord LengthTypeWords = 0
AnyLengthWord is the zero value of LengthTypeWords and selects the full length range (any category). It is the length counterpart of the Any zero value used by the WordsPT flexion enums (Gender, Number, Degree).
const BigLengthWords LengthTypeWords = 3
BigLengthWords represents big length words, 9 to 30 chars.
const MediumLengthWords LengthTypeWords = 2
MediumLengthWords represents medium length words, 5 to 8 chars.
const SmallLengthWord LengthTypeWords = 1
SmallLengthWord represents small length words, 1 to 4 chars.
type Mood ¶ added in v0.2.0
type Mood uint8
Mood is the grammatical mood option of a generated pt-PT verb. Its zero value, AnyMood, means "choose a valid mood at random". The finite moods (Indicative, Subjunctive, ImperativeAffirmative, ImperativeNegative) inflect for person and number; the indicative and subjunctive additionally inflect for Tense. The non-finite moods (Infinitive, Gerund, Participle) take no tense; of these, only the personal infinitive inflects for person and number.
const ( // AnyMood is the zero value of [Mood] and selects a random valid mood. AnyMood Mood = iota // Indicative selects the indicative mood (finite). Indicative // Subjunctive selects the subjunctive (conjuntivo) mood (finite). Subjunctive // ImperativeAffirmative selects the affirmative imperative mood (finite). ImperativeAffirmative // ImperativeNegative selects the negative imperative mood. In pt-PT the negated // command is periphrastic ("não" + present subjunctive); WordsPT, a single-word // generator, produces only the verb form, without the negating particle. ImperativeNegative // Infinitive selects the infinitive mood: the impersonal infinitive (falar) or, // for a concrete person and number, the inflected personal infinitive. Infinitive // Gerund selects the gerund (gerúndio): the invariable -ndo form (falando). Gerund // Participle selects the past participle: the invariable masculine singular form // (falado, comido, partido). Participle )
type Number ¶ added in v0.2.0
type Number uint8
Number is the grammatical number option of a generated nominal pt-PT word. Its zero value, AnyNumber, means "choose a valid number at random".
type Person ¶ added in v0.2.0
type Person uint8
Person is the grammatical person option of a generated pt-PT verb. Its zero value, AnyPerson, means "choose a valid person at random". WordsPT follows current pt-PT usage without the archaic second person plural ("vós"): a second person plural request normalizes to the third person plural (see the package documentation, Normalization rule N1).
type Tense ¶ added in v0.2.0
type Tense uint8
Tense is the grammatical tense option of a generated pt-PT verb. Its zero value, AnyTense, means "choose a valid tense at random for the resolved mood". Tense applies only to the finite moods; on the non-finite and imperative moods a requested tense is ignored.
const ( // AnyTense is the zero value of [Tense] and selects a random valid tense. AnyTense Tense = iota // Present selects the present tense. Present // Imperfect selects the imperfect past tense. Imperfect // Preterite selects the preterite (perfect past) tense. Preterite // Future selects the future tense. Future // Conditional selects the conditional tense. Conditional )
Source Files
¶
- bool.go
- dates.go
- doc.go
- generator.go
- init.go
- numbers.go
- strings.go
- words.go
- wordspt.go
- wordspt_accent.go
- wordspt_adjective.go
- wordspt_adverb.go
- wordspt_closed.go
- wordspt_data.go
- wordspt_inflection.go
- wordspt_noun.go
- wordspt_plural.go
- wordspt_skew_table.go
- wordspt_stem.go
- wordspt_verb.go
- wordspt_verb_public.go
- wordspt_word.go