faker

package module
v0.0.0-...-ee784ce Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2026 License: BSD-3-Clause Imports: 8 Imported by: 0

README

go-ruby-faker/faker

faker — go-ruby-faker

Docs License Go Coverage

A pure-Go (no cgo) reimplementation of Ruby's faker gem (3.8.0) — a seeded, MRI-faithful fake-data generator. Given the same seed, it reproduces the gem's draw sequence bit-for-bit, because its random core is an exact port of Ruby's Random (MT19937 with init_by_array seeding and the mask-and-reject integer scheme) and of Array#sample / Array#shuffle.

It ships the gem's en i18n data tables embedded, so it is complete offline — no network, no Ruby runtime, CGO=0 on all six 64-bit Go targets (amd64, arm64, riscv64, loong64, ppc64le, s390x). It is the fake-data generator for go-embedded-ruby, but is a standalone, reusable module — a sibling of go-ruby-regexp and go-ruby-erb.

The deterministic-seed contract

The gem's key correctness property is that

Faker::Config.random = Random.new(SEED)

makes the sequence of generated values reproducible. This package mirrors it:

f := faker.NewSeeded(42)             // Faker::Config.random = Random.new(42)
f.Name().Name()                      // Faker::Name.name
f.Internet().Email()                 // Faker::Internet.email

faker.NewRandom(SEED) is a bit-exact port of Random.new(SEED): its raw rand, rand(n), rand(a..b), sample(random:) and shuffle(random:) outputs match MRI. The suite pins ~2000 values across seven seeds to live gem output.

Generators

Name · Internet · Address · PhoneNumber · Lorem · Number · Company · Commerce · Color · Boolean · Date · Time, plus the Faker::Base helpers Sample / SampleN / Shuffle / Fetch / Numerify / Letterify / Bothify / Regexify / Parse, the Faker::Config locale + RNG accessors, and the unique modifier (NewUnique — retry + exhaustion error).

Class Methods
Name name, name_with_middle, first_name, male/female/neutral first_name, last_name, prefix, suffix, initials
Internet username, email, domain_word, domain_name, domain_suffix, slug, url, ip_v4/ip_v6/mac_address, password
Address city, street_name/address, secondary_address, building_number, community, zip_code (zip/postcode), state, state_abbr, country, country_code(_long), time_zone, full_address, latitude, longitude
PhoneNumber phone_number, cell_phone, country_code, area_code, exchange_code, subscriber_number/extension, with_country_code variants
Lorem word, words, characters, sentence, sentences, paragraph, paragraphs
Number number, decimal, digit, non_zero_digit, hexadecimal, binary, between, positive, negative, normal
Company name, suffix, industry, buzzword, catch_phrase, bs
Commerce product_name, department, price
Color color_name, hex_color, rgb_color
Boolean boolean(true_ratio)
Date / Time between, forward, backward

Seed-parity scope (honest)

Exact-sequence parity with the gem holds for every generator whose randomness flows through INTEGER draws and sample/shuffle selections: Name, Address (city/street/zip/state/country/full_address), PhoneNumber, Lorem, Company, Commerce.product_name/department, Color.color_name, Boolean, Number's integer paths, Internet's table-driven paths (username/email/domain/url/slug), and Date.between/forward/backward (whole-day integer arithmetic).

Distribution / data-table / format parity only (not bit-exact sequence) applies where the value derives from a FLOAT-range draw, because MRI's Random#rand(lo..hi) for float ranges uses a higher-precision internal algorithm this port does not reproduce: Address.latitude/longitude, Number.between/positive/negative/normal with non-integer bounds, Commerce.price, Color.hex_color, and Time.between/forward/backward. These match the gem's data tables, formats and statistical distribution; their exact per-seed value may differ in low-order digits.

Tests & coverage

GOWORK=off go test -race -cover ./...

The suite is 100% statement coverage. The deterministic, Ruby-free tests cover every branch on their own (so the Windows and qemu cross-arch CI lanes hold the gate); where the ruby binary and the faker gem are present, the oracle vectors in oracle_test.go pin the seeded output to live gem 3.8.0 values.

License

BSD-3-Clause — see LICENSE. Copyright (c) 2026, the go-ruby-faker/faker authors.

WebAssembly

Being pure Go (CGO=0), this library also compiles to WebAssembly — both GOOS=js GOARCH=wasm (browser / Node.js) and GOOS=wasip1 GOARCH=wasm (WASI). CI builds both targets on every push, alongside the six 64-bit native/qemu arches.

GOOS=js     GOARCH=wasm go build ./...   # browser / Node
GOOS=wasip1 GOARCH=wasm go build ./...   # WASI (wasmtime, wasmer, wasmedge, …)

Documentation

Overview

Package faker is a pure-Go (CGO=0) port of the Ruby `faker` gem: a seeded, MRI-faithful fake-data generator.

Deterministic seeding contract

The gem's key correctness property is that, given

Faker::Config.random = Random.new(SEED)

the sequence of generated values is reproducible. This package mirrors that: construct a Faker with New over a Random seeded by NewRandom and the draw sequence reproduces MRI's, because Random is a bit-exact port of Ruby's MT19937 (including init_by_array seeding and the mask-and-reject integer scheme) and the Array#sample / Array#shuffle helpers replay MRI's algorithms.

Seed-parity scope (honest)

Exact-sequence parity with the gem holds for every generator whose randomness flows through INTEGER draws and single/sampled selections: Name, Address (city/street/zip/state/country/full_address), PhoneNumber, Lorem, Company, Commerce.product_name/department, Color.color_name, Boolean, Number's integer paths (number/digit/hexadecimal/binary/decimal), Internet's table-driven paths, and Date.between/forward/backward (Julian-day integer arithmetic).

Distribution/format parity only (NOT bit-exact sequence) applies where the value derives from a FLOAT-range draw, because MRI's Random#rand(lo..hi) for float ranges uses a higher-precision internal algorithm this port does not reproduce: Address.latitude/longitude, Number.between/within/positive/ negative/normal with non-integer bounds, Commerce.price, and Time.between/ forward/backward. These match the gem's data tables, formats and statistical distribution; their exact per-seed value may differ in low-order digits.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AddressGen

type AddressGen struct {
	// contains filtered or unexported fields
}

AddressGen is Faker::Address.

func (*AddressGen) BuildingNumber

func (a *AddressGen) BuildingNumber() string

BuildingNumber produces a building number (Faker::Address.building_number).

func (*AddressGen) City

func (a *AddressGen) City() string

City produces a city name (Faker::Address.city).

func (*AddressGen) CityPrefix

func (a *AddressGen) CityPrefix() string

CityPrefix produces a city prefix (Faker::Address.city_prefix).

func (*AddressGen) CitySuffix

func (a *AddressGen) CitySuffix() string

CitySuffix produces a city suffix (Faker::Address.city_suffix).

func (*AddressGen) Community

func (a *AddressGen) Community() string

Community produces a community name (Faker::Address.community).

func (*AddressGen) Country

func (a *AddressGen) Country() string

Country produces a country name (Faker::Address.country).

func (*AddressGen) CountryCode

func (a *AddressGen) CountryCode() string

CountryCode produces an ISO 3166 alpha-2 country code (Faker::Address.country_code).

func (*AddressGen) CountryCodeLong

func (a *AddressGen) CountryCodeLong() string

CountryCodeLong produces an ISO 3166 alpha-3 country code.

func (*AddressGen) FullAddress

func (a *AddressGen) FullAddress() string

FullAddress produces a full address (Faker::Address.full_address).

func (*AddressGen) Latitude

func (a *AddressGen) Latitude() float64

Latitude produces a latitude in [-90, 90). Distribution parity only (float draw).

func (*AddressGen) Longitude

func (a *AddressGen) Longitude() float64

Longitude produces a longitude in [-180, 180). Distribution parity only.

func (*AddressGen) Postcode

func (a *AddressGen) Postcode() string

Postcode is an alias for ZipCode.

func (*AddressGen) SecondaryAddress

func (a *AddressGen) SecondaryAddress() string

SecondaryAddress produces a secondary address (Faker::Address.secondary_address).

func (*AddressGen) State

func (a *AddressGen) State() string

State produces a state name (Faker::Address.state).

func (*AddressGen) StateAbbr

func (a *AddressGen) StateAbbr() string

StateAbbr produces a state abbreviation (Faker::Address.state_abbr).

func (*AddressGen) StreetAddress

func (a *AddressGen) StreetAddress() string

StreetAddress produces a street address (Faker::Address.street_address).

func (*AddressGen) StreetName

func (a *AddressGen) StreetName() string

StreetName produces a street name (Faker::Address.street_name).

func (*AddressGen) StreetSuffix

func (a *AddressGen) StreetSuffix() string

StreetSuffix produces a street suffix (Faker::Address.street_suffix).

func (*AddressGen) TimeZone

func (a *AddressGen) TimeZone() string

TimeZone produces a time-zone name (Faker::Address.time_zone).

func (*AddressGen) Zip

func (a *AddressGen) Zip() string

Zip is an alias for ZipCode.

func (*AddressGen) ZipCode

func (a *AddressGen) ZipCode() string

ZipCode produces a zip/postal code (Faker::Address.zip_code). The fetched postcode pattern is letterified then numerified with leading zeros allowed.

type BooleanGen

type BooleanGen struct {
	// contains filtered or unexported fields
}

BooleanGen is Faker::Boolean.

func (*BooleanGen) Boolean

func (b *BooleanGen) Boolean(trueRatio float64) bool

Boolean returns a bool that is true with probability trueRatio (Faker::Boolean.boolean). trueRatio 0.5 gives an even coin.

type ColorGen

type ColorGen struct {
	// contains filtered or unexported fields
}

ColorGen is Faker::Color.

func (*ColorGen) ColorName

func (c *ColorGen) ColorName() string

ColorName produces the name of a color (Faker::Color.color_name).

func (*ColorGen) HexColor

func (c *ColorGen) HexColor() string

HexColor produces a random hex color "#rrggbb" via HSL conversion (Faker::Color.hex_color with no fixed components). Distribution parity: saturation/lightness derive from float draws.

func (*ColorGen) RGBColor

func (c *ColorGen) RGBColor() [3]int

RGBColor produces an [r,g,b] triple (Faker::Color.rgb_color).

type CommerceGen

type CommerceGen struct {
	// contains filtered or unexported fields
}

CommerceGen is Faker::Commerce.

func (*CommerceGen) Department

func (c *CommerceGen) Department(max int, fixedAmount bool) string

Department produces a department name. With fixedAmount the number of categories is exactly max; otherwise it is 1 + rand(max) (Faker::Commerce.department). Multiple categories are joined "a, b & c".

func (*CommerceGen) Price

func (c *CommerceGen) Price(max float64) float64

Price produces a price in the half-open range [0, max), floored to cents (Faker::Commerce.price). Distribution parity only (float-range draw).

func (*CommerceGen) ProductName

func (c *CommerceGen) ProductName() string

ProductName produces "Adjective Material Product" (Faker::Commerce.product_name).

type CompanyGen

type CompanyGen struct {
	// contains filtered or unexported fields
}

CompanyGen is Faker::Company.

func (*CompanyGen) BS

func (c *CompanyGen) BS() string

BS produces some company BS, one word from each bs column (Faker::Company.bs).

func (*CompanyGen) Buzzword

func (c *CompanyGen) Buzzword() string

Buzzword produces a single buzzword (Faker::Company.buzzword).

func (*CompanyGen) CatchPhrase

func (c *CompanyGen) CatchPhrase() string

CatchPhrase produces a company catch phrase by sampling one word from each buzzword column (Faker::Company.catch_phrase).

func (*CompanyGen) Industry

func (c *CompanyGen) Industry() string

Industry produces a company industry (Faker::Company.industry).

func (*CompanyGen) Name

func (c *CompanyGen) Name() string

Name produces a company name (Faker::Company.name).

func (*CompanyGen) Suffix

func (c *CompanyGen) Suffix() string

Suffix produces a company suffix (Faker::Company.suffix).

type DateGen

type DateGen struct {
	// contains filtered or unexported fields
}

DateGen is Faker::Date. Date arithmetic uses whole-day (Julian-day) integer draws, so DateGen is bit-exact with the gem's seeded sequence.

func (*DateGen) Backward

func (d *DateGen) Backward(base time.Time, days int) time.Time

Backward returns a date 1..days in the past from base (Faker::Date.backward).

func (*DateGen) Between

func (d *DateGen) Between(from, to time.Time) time.Time

Between returns a date in [from, to] inclusive (Faker::Date.between). Both bounds are truncated to whole days; the draw is an exact integer day offset.

func (*DateGen) Forward

func (d *DateGen) Forward(base time.Time, days int) time.Time

Forward returns a date 1..days into the future from base (Faker::Date.forward).

type Faker

type Faker struct {
	// contains filtered or unexported fields
}

Faker holds the configuration (locale + RNG) and exposes the generators. It corresponds to Faker::Config plus the Faker::Base class methods.

func New

func New(rng *Random) *Faker

New returns a Faker using the given seeded RNG and the default ("en") locale.

func NewSeeded

func NewSeeded(seed int64) *Faker

NewSeeded is a convenience for New(NewRandom(seed)).

func (*Faker) Address

func (f *Faker) Address() *AddressGen

Address returns the Faker::Address generator.

func (*Faker) Boolean

func (f *Faker) Boolean() *BooleanGen

Boolean returns the Faker::Boolean generator.

func (*Faker) Bothify

func (f *Faker) Bothify(s string) string

Bothify mirrors Faker::Base.bothify: numerify then letterify.

func (*Faker) Color

func (f *Faker) Color() *ColorGen

Color returns the Faker::Color generator.

func (*Faker) Commerce

func (f *Faker) Commerce() *CommerceGen

Commerce returns the Faker::Commerce generator.

func (*Faker) Company

func (f *Faker) Company() *CompanyGen

Company returns the Faker::Company generator.

func (*Faker) Date

func (f *Faker) Date() *DateGen

Date returns the Faker::Date generator.

func (*Faker) Fetch

func (f *Faker) Fetch(key string) string

Fetch mirrors Faker::Base.fetch: sample one value from a locale array; if the chosen value is a /regex/ literal, regexify it.

func (*Faker) FetchAll

func (f *Faker) FetchAll(key string) []string

FetchAll mirrors Faker::Base.fetch_all: the full locale array for a key.

func (*Faker) Internet

func (f *Faker) Internet() *InternetGen

Internet returns the Faker::Internet generator.

func (*Faker) Letterify

func (f *Faker) Letterify(s string) string

Letterify mirrors Faker::Base.letterify: each '?' becomes an uppercase A–Z.

func (*Faker) Locale

func (f *Faker) Locale() string

Locale reports the active locale (Faker::Config.locale).

func (*Faker) Lorem

func (f *Faker) Lorem() *LoremGen

Lorem returns the Faker::Lorem generator.

func (*Faker) Name

func (f *Faker) Name() *NameGen

Name returns the Faker::Name generator.

func (*Faker) Number

func (f *Faker) Number() *NumberGen

Number returns the Faker::Number generator.

func (*Faker) Numerify

func (f *Faker) Numerify(s string, leadingZero bool) string

Numerify mirrors Faker::Base.numerify: each '#' becomes a digit. By default the FIRST '#' becomes 1..9 (no leading zero) and the rest 0..9; with leadingZero true every '#' becomes 0..9.

func (*Faker) Parse

func (f *Faker) Parse(key string) string

Parse mirrors Faker::Base.parse: fetch a format string from the locale and expand its #{token} placeholders by dispatching to generators (Name., Address., …) or recursive locale lookups. If nothing parses, the string is numerified.

func (*Faker) PhoneNumber

func (f *Faker) PhoneNumber() *PhoneNumberGen

PhoneNumber returns the Faker::PhoneNumber generator.

func (*Faker) Random

func (f *Faker) Random() *Random

Random returns the underlying RNG (Faker::Config.random).

func (*Faker) Regexify

func (f *Faker) Regexify(reg string) string

Regexify mirrors Faker::Base.regexify: a deliberately simple regex generator matching the gem's supported subset (anchors, {n}/{m,n}, ?, [...] classes and ranges, (a|b) alternations, \d, \w). It draws with the same Array#sample over the configured RNG, so seeded output matches the gem for the patterns it supports.

func (*Faker) Sample

func (f *Faker) Sample(list []string) string

Sample mirrors Faker::Base.sample(list): a single random element.

func (*Faker) SampleN

func (f *Faker) SampleN(list []string, n int) []string

SampleN mirrors Faker::Base.sample(list, n): n random elements.

func (*Faker) SetLocale

func (f *Faker) SetLocale(loc string)

SetLocale sets the locale. Only "en" ships embedded data; other locales fall back to "en" (mirroring the gem's en fallback for missing translations).

func (*Faker) SetRandom

func (f *Faker) SetRandom(r *Random)

SetRandom replaces the RNG (Faker::Config.random=).

func (*Faker) Shuffle

func (f *Faker) Shuffle(list []string) []string

Shuffle mirrors Faker::Base.shuffle(list).

func (*Faker) Time

func (f *Faker) Time() *TimeGen

Time returns the Faker::Time generator.

type InternetGen

type InternetGen struct {
	// contains filtered or unexported fields
}

InternetGen is Faker::Internet.

func (*InternetGen) DomainName

func (in *InternetGen) DomainName() string

DomainName produces "word.suffix" using a safe suffix (Faker::Internet.domain_name).

func (*InternetGen) DomainSuffix

func (in *InternetGen) DomainSuffix() string

DomainSuffix produces a domain suffix (Faker::Internet.domain_suffix).

func (*InternetGen) DomainWord

func (in *InternetGen) DomainWord() string

DomainWord produces the leading word of a domain (Faker::Internet.domain_word): the prepared first token of a company name.

func (*InternetGen) Email

func (in *InternetGen) Email() string

Email produces an email address (Faker::Internet.email): a username local part at a generated domain.

func (*InternetGen) IPv4Address

func (in *InternetGen) IPv4Address() string

IPv4Address produces a dotted IPv4 address (Faker::Internet.ip_v4_address).

func (*InternetGen) IPv6Address

func (in *InternetGen) IPv6Address() string

IPv6Address produces a colon-separated IPv6 address (Faker::Internet.ip_v6_address).

func (*InternetGen) MacAddress

func (in *InternetGen) MacAddress(prefix string) string

MacAddress produces a colon-separated MAC address (Faker::Internet.mac_address). prefix may be a partial "aa" or "aa:bb" hex prefix.

func (*InternetGen) Password

func (in *InternetGen) Password(minLength, maxLength int, mixCase, specialChars bool) string

Password produces a password between minLength and maxLength characters (Faker::Internet.password). With mixCase an uppercase letter is guaranteed; with specialChars a special character is guaranteed. The result is shuffled.

func (*InternetGen) SafeDomainSuffix

func (in *InternetGen) SafeDomainSuffix() string

SafeDomainSuffix produces a safe domain suffix ("example"/"test").

func (*InternetGen) Slug

func (in *InternetGen) Slug() string

Slug produces a URL slug of two words joined by '-' or '_' (Faker::Internet.slug).

func (*InternetGen) URL

func (in *InternetGen) URL() string

URL produces "http://domain/username" (Faker::Internet.url).

func (*InternetGen) Username

func (in *InternetGen) Username() string

Username produces a username (Faker::Internet.username with no specifier).

Faithful to the gem's sample over two freshly-evaluated options:

sample([
  Char.prepare(Faker::Name.first_name),
  [Faker::Name.first_name, Faker::Name.last_name].map { Char.prepare }.join(sample(separators)),
])

so the draw sequence is first_name (option 0), then first_name + last_name + sample(separators) (option 1), then the 2-element sample, then downcase. Note the two options each draw their OWN first_name — they are not shared.

type LoremGen

type LoremGen struct {
	// contains filtered or unexported fields
}

LoremGen is Faker::Lorem.

func (*LoremGen) Characters

func (l *LoremGen) Characters(number int) string

Characters returns number random alphanumeric characters (Faker::Lorem.characters), drawing from a-z and 0-9.

func (*LoremGen) Paragraph

func (l *LoremGen) Paragraph(sentenceCount int, supplemental bool) string

Paragraph returns a paragraph of sentenceCount sentences joined by spaces.

func (*LoremGen) Paragraphs

func (l *LoremGen) Paragraphs(number int, supplemental bool) []string

Paragraphs returns number paragraphs (each of 3 sentences).

func (*LoremGen) Sentence

func (l *LoremGen) Sentence(wordCount int, supplemental bool) string

Sentence returns a capitalized sentence of wordCount words ended with the locale period.

func (*LoremGen) Sentences

func (l *LoremGen) Sentences(number int, supplemental bool) []string

Sentences returns number sentences (each of 3 words, matching the gem).

func (*LoremGen) Word

func (l *LoremGen) Word() string

Word returns a single random lorem word (Faker::Lorem.word).

func (*LoremGen) Words

func (l *LoremGen) Words(number int, supplemental bool) []string

Words returns number random lorem words. With supplemental true the supplemental word list is appended to the pool first. This mirrors the gem's word_list *= ((num/len)+1) expansion before sampling, so seeded output matches even when number exceeds the pool size.

type NameGen

type NameGen struct {
	// contains filtered or unexported fields
}

NameGen is Faker::Name.

func (*NameGen) FemaleFirstName

func (n *NameGen) FemaleFirstName() string

FemaleFirstName produces a random female first name.

func (*NameGen) FirstName

func (n *NameGen) FirstName() string

FirstName produces a random first name.

This mirrors a subtle quirk of the gem: Faker::Name.first_name evaluates parse('name.first_name') TWICE — once for the `.empty?` guard and again to produce the return value — so it consumes two parse cycles' worth of draws. Reproducing that double evaluation is required for seed-exact parity.

func (*NameGen) Initials

func (n *NameGen) Initials(number int) string

Initials produces random uppercase initials (Faker::Name.initials).

func (*NameGen) LastName

func (n *NameGen) LastName() string

LastName produces a random last name.

func (*NameGen) MaleFirstName

func (n *NameGen) MaleFirstName() string

MaleFirstName produces a random male first name.

func (*NameGen) Name

func (n *NameGen) Name() string

Name produces a random full name (Faker::Name.name).

func (*NameGen) NameWithMiddle

func (n *NameGen) NameWithMiddle() string

NameWithMiddle produces a name with a middle name.

func (*NameGen) NeutralFirstName

func (n *NameGen) NeutralFirstName() string

NeutralFirstName produces a random gender-neutral first name.

func (*NameGen) Prefix

func (n *NameGen) Prefix() string

Prefix produces a random name prefix (e.g. "Mr.").

func (*NameGen) Suffix

func (n *NameGen) Suffix() string

Suffix produces a random name suffix (e.g. "IV").

type NumberGen

type NumberGen struct {
	// contains filtered or unexported fields
}

NumberGen is Faker::Number.

func (*NumberGen) Between

func (n *NumberGen) Between(from, to float64) float64

Between returns a float in [from, to] (inclusive). NOTE: float-range distribution parity only, not bit-exact sequence (see package doc).

func (*NumberGen) BetweenInt

func (n *NumberGen) BetweenInt(from, to int) int

BetweenInt returns an integer in [from, to] (inclusive) — bit-exact with the gem when both bounds are integers.

func (*NumberGen) Binary

func (n *NumberGen) Binary(digits int) string

Binary produces a binary string of the given length (Faker::Number.binary).

func (*NumberGen) Decimal

func (n *NumberGen) Decimal(lDigits, rDigits int) float64

Decimal produces a float with lDigits integer digits and rDigits fractional digits (Faker::Number.decimal). The last fractional digit is non-zero.

func (*NumberGen) Digit

func (n *NumberGen) Digit() int

Digit produces a single-digit integer 0..9 (Faker::Number.digit).

func (*NumberGen) Hexadecimal

func (n *NumberGen) Hexadecimal(digits int) string

Hexadecimal produces a lowercase hex string of the given length (Faker::Number.hexadecimal).

func (*NumberGen) Negative

func (n *NumberGen) Negative(from, to float64) float64

Negative returns a negative float in the range (Faker::Number.negative).

func (*NumberGen) NonZeroDigit

func (n *NumberGen) NonZeroDigit() int

NonZeroDigit produces a non-zero single-digit integer 1..9.

func (*NumberGen) Normal

func (n *NumberGen) Normal(mean, stddev float64) float64

Normal returns a Gaussian float given mean and standard deviation (Faker::Number.normal, Box–Muller). Distribution parity only.

func (*NumberGen) Number

func (n *NumberGen) Number(digits int) int64

Number produces a random integer with the given number of digits. The first digit is non-zero (1..9). Returns 0 for digits < 1 (the gem returns nil).

func (*NumberGen) Positive

func (n *NumberGen) Positive(from, to float64) float64

Positive returns a positive float in the range (Faker::Number.positive).

type PhoneNumberGen

type PhoneNumberGen struct {
	// contains filtered or unexported fields
}

PhoneNumberGen is Faker::PhoneNumber.

func (*PhoneNumberGen) AreaCode

func (p *PhoneNumberGen) AreaCode() string

AreaCode produces an area code (Faker::PhoneNumber.area_code).

func (*PhoneNumberGen) CellPhone

func (p *PhoneNumberGen) CellPhone() string

CellPhone produces a cell phone number (Faker::PhoneNumber.cell_phone).

func (*PhoneNumberGen) CellPhoneWithCountryCode

func (p *PhoneNumberGen) CellPhoneWithCountryCode() string

CellPhoneWithCountryCode prefixes a country code to a cell number.

func (*PhoneNumberGen) CountryCode

func (p *PhoneNumberGen) CountryCode() string

CountryCode produces "+NN" (Faker::PhoneNumber.country_code).

func (*PhoneNumberGen) ExchangeCode

func (p *PhoneNumberGen) ExchangeCode() string

ExchangeCode produces an exchange code (Faker::PhoneNumber.exchange_code).

func (*PhoneNumberGen) Extension

func (p *PhoneNumberGen) Extension(length int) string

Extension is an alias for SubscriberNumber.

func (*PhoneNumberGen) PhoneNumber

func (p *PhoneNumberGen) PhoneNumber() string

PhoneNumber produces a phone number in a random format (Faker::PhoneNumber.phone_number).

func (*PhoneNumberGen) PhoneNumberWithCountryCode

func (p *PhoneNumberGen) PhoneNumberWithCountryCode() string

PhoneNumberWithCountryCode prefixes a country code (Faker::PhoneNumber.phone_number_with_country_code).

func (*PhoneNumberGen) SubscriberNumber

func (p *PhoneNumberGen) SubscriberNumber(length int) string

SubscriberNumber produces a numeric subscriber number of the given length (Faker::PhoneNumber.subscriber_number / extension). It mirrors the gem's PositionalGenerator int(length:): a single range [10^(n-1), 10^n - 1] is sampled from a one-element array (consuming one draw) and then a value in that inclusive range is drawn.

type Random

type Random struct {
	// contains filtered or unexported fields
}

Random is Ruby's Random: an MT19937 generator seeded exactly as MRI does (init_by_array over the seed's 32-bit little-endian words), so seeded output matches MRI bit for bit. This is the keystone of Faker's deterministic-seed contract: NewRandom(seed) reproduces the same draw sequence MRI's Random.new(seed) produces.

func NewRandom

func NewRandom(seed int64) *Random

NewRandom returns a Random seeded exactly as MRI's Random.new(seed).

func NewRandomEntropy

func NewRandomEntropy() *Random

NewRandomEntropy draws a non-deterministic seed (matching MRI's entropy-seeded Random.new with no argument) and returns a seeded Random.

func (*Random) Bytes

func (r *Random) Bytes(n int) []byte

Bytes returns n pseudo-random bytes, matching Random#bytes(n) (little-endian words from genrand_int32).

func (*Random) Float

func (r *Random) Float() float64

Float mirrors Random#rand with no argument: a float in [0, 1).

func (*Random) FloatInRange

func (r *Random) FloatInRange(lo, hi float64) float64

FloatInRange returns lo + res53*(hi-lo). NOTE: this is an approximation of MRI's Random#rand(lo..hi) for FLOAT ranges; MRI uses a higher-precision internal float-range algorithm that this does not bit-match. Integer-range draws (IntInRange) ARE bit-exact; see the package doc for the seed-parity scope.

func (*Random) FloatScaled

func (r *Random) FloatScaled(f float64) float64

FloatScaled mirrors Random#rand(f) for a positive float f: res53 * f.

func (*Random) IntInRange

func (r *Random) IntInRange(lo, hi int) int

IntInRange mirrors Random#rand(lo..hi) (inclusive) over integers.

func (*Random) Intn

func (r *Random) Intn(n int) int

Intn mirrors Random#rand(n) for a positive integer n: an integer in [0, n). It panics for n <= 0, matching MRI's ArgumentError.

func (*Random) Seed

func (r *Random) Seed() int64

Seed reports the seed the generator was created with.

type RetriesExhaustedError

type RetriesExhaustedError struct {
	Retries int
}

RetriesExhaustedError is returned (as the error value) when Unique cannot find a fresh value within the retry budget, mirroring the gem's Faker::UniqueGenerator::RetryLimitExceeded.

func (*RetriesExhaustedError) Error

func (e *RetriesExhaustedError) Error() string

type TimeGen

type TimeGen struct {
	// contains filtered or unexported fields
}

TimeGen is Faker::Time. Time draws use float ranges, so TimeGen matches the gem's data/format/distribution but NOT its exact per-seed value (see package doc on seed-parity scope).

func (*TimeGen) Backward

func (tg *TimeGen) Backward(base time.Time, days int) time.Time

Backward returns a time 1..days in the past (Faker::Time.backward).

func (*TimeGen) Between

func (tg *TimeGen) Between(from, to time.Time) time.Time

Between returns a time in [from, to] (Faker::Time.between). Distribution parity only.

func (*TimeGen) Forward

func (tg *TimeGen) Forward(base time.Time, days int) time.Time

Forward returns a time 1..days into the future (Faker::Time.forward).

type Unique

type Unique struct {
	// contains filtered or unexported fields
}

Unique wraps a generator function so each returned value is distinct, mirroring the gem's `Faker::Name.unique.first_name` modifier. It calls gen until it produces a value not seen before, giving up after maxRetries attempts.

Pass maxRetries <= 0 to use the gem's default of 10_000.

func NewUnique

func NewUnique(maxRetries int) *Unique

NewUnique returns a Unique tracker. maxRetries <= 0 uses the gem default 10000.

func (*Unique) Clear

func (u *Unique) Clear()

Clear forgets all previously seen values (Faker::UniqueGenerator#clear).

func (*Unique) Next

func (u *Unique) Next(gen func() string) (string, error)

Next runs gen until it yields a value not previously returned by this tracker, or returns a *RetriesExhaustedError after maxRetries attempts.

Jump to

Keyboard shortcuts

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