Skip to content

Generator Reference ​

Every module method returns a Generator<T> — an immutable, reusable factory. Generators don't produce anything until they're invoked: Generate(), an implicit cast to T, or a faker's Get() call them for you.

csharp
var fullName = forge.Person.FullName();   // Generator<string>
var name = fullName.Generate();           // explicit
string other = fullName;                  // implicit conversion

Basic ​

Literal and functional values.

MemberSignatureNotes
LiteralLiteral<T>(T literal)Always returns the same value.
FuncFunc<T>(Func<T> func)Calls the function each time it's used.
csharp
FirstName = f => f.Basic.Literal("Ada"),
CreatedBy = f => f.Basic.Func(() => Environment.UserName),

Random ​

Selection and distribution tools.

MemberSignatureNotes
CoinTossCoinToss()bool, fair 50/50.
PickPick<T>(params T[] items)Uniform single draw from a fixed list.
PickPick<T>(T[] items, int count)Array of exactly count draws (with replacement).
PickPick<T>(T[] items, int minCount, int maxCount)Array of minCount..maxCount draws.
PickUniquePickUnique<T>(T[] items, int count) / (items, minCount, maxCount)Draws without replacement.
Pick (enum)Pick<T>() where T : struct, EnumUniform enum value.
NumberNumber<T>(T? min = null, T? max = null)Uniform numeric, inclusive; defaults to the type's min/max. Any INumber<T>.
UniformUniform<T>(T? min = null, T? max = null)Alias of Number.
NormalNormal<T>(T? mean = null, T? stdDev = null)Mean 0 / std-dev 1 by default.
LogNormalLogNormal<T>(T? mean = null, T? stdDev = null)Positive values from the underlying normal.
ExponentialExponential<T>(T? rate = null)Non-negative; rate 1 by default.
BernoulliBernoulli<T>(T? probability = null)Produces 1 with probability (0.5 by default), else 0.
PoissonPoisson<T>(T? lambda = null)Non-negative integer values; lambda 1 by default.
WeightedPickWeightedPick<T>(T[] items, float[] weights)One weight per item, higher = more likely.
WeightedPickWeightedPick<T>((T item, float weight)[] items)Item/weight tuple form.
DiceDice(string expression, RoundingMode mode = Round)Classic dice notation, e.g. "2d6+1d10-3".
csharp
Gender = f => f.Random.Pick("M", "F", "X"),
Handful = f => f.Random.Pick(new[] { 1, 2, 3, 4 }, 2),
EnumVal = f => f.Random.Pick<MyEnum>(),
Score = f => f.Random.Dice("2d6+1d10-3"),

Temporal ​

MemberSignatureNotes
BetweenBetween(DateTime? min = null, DateTime? max = null)Inclusive; defaults to DateTime.MinValue..MaxValue.
PastPast(DateTime? earliest = null)earliest..DateTime.UtcNow; default earliest = one year ago.
FutureFuture(DateTime? latest = null)DateTime.UtcNow..latest; default latest = one year from now.
DateBetween / DateInPast / DateInFutureSame shapes for DateOnly.
TimeBetweenTimeBetween(TimeOnly? min = null, TimeOnly? max = null)Time of day.
DateTimeOffsetBetween / InPast / InFutureSame shapes for DateTimeOffset.DateTimeOffset.UtcNow used as the reference.
TimeSpanBetweenTimeSpanBetween(TimeSpan? min = null, TimeSpan? max = null)Durations.
csharp
DateOfBirth = f => f.Temporal.Between(new DateTime(1950, 1, 1), DateTime.Today),
LastLogin = f => f.Temporal.Past(),

Text ​

MemberSignatureNotes
AlphanumericAlphanumeric(int length) or (int min, int max)[A-Za-z0-9].
AlphaAlpha(int length) or (int min, int max)Letters only.
PronounceablePronounceable(int length) or (int min, int max)Readable pseudo-words; the length is in syllables.
LoremLorem(int length, LoremIpsumGenerator.Options? options = null) or (min, max, options)Classic lorem ipsum; length in words.
WaffleWaffle(int sentences, WaffleStyle style = Technical)Natural-sounding filler.
HexHex(int length) or (int min, int max)Hex digits.
GuidGuid(GuidGenerator.Kind kind = V4)V4 (random) or V7 (time-ordered).
TemplateTemplate(string template)# digit, ? letter, * alnum; \ escapes the next char.
CharChar(CharKind kind = Printable)Single char: Printable, Alphanumeric, Alphabetical, Numeric, …
CharsChars(int count, CharKind kind = Printable) or (min, max, kind)char[].
EmojiEmoji()A single emoji.
EmojiRunesEmojiRunes()The emoji as a Rune[] (handles multi-codepoint emoji).
csharp
Id = f => f.Text.Guid(GuidGenerator.Kind.V7),
Sku = f => f.Text.Template("###-???-***"),
Bio = f => f.Text.Waffle(2),

Internet ​

MemberSignatureNotes
UsernameUsername(float prefixChance = 0.5f, float suffixChance = 0.5f, float leetChance = 0.1f)e.g. TribalFox42.
DomainDomain(float ccSldChance = 0.0f)example.com style.
EmailEmail(EmailKind kind = Random, IGenerator<string>? provider = null)See below.
csharp
Email = f => f.Internet.Email(),
Contact = f => f.Internet.Email(EmailKind.Example),
WorkEmail = f => f.Internet.Email(EmailKind.Known, f.Text.Alpha(8).ToLower()),

Email's second parameter supplies the local part (the name before @). It's named provider for historical reasons but it is a generator for the username — pass a name generator to base the address on real names. When omitted, a username generator is used.

EmailKind ​

KindBehavior
KnownReal provider domains (gmail.com, icloud.com, …) from locale data.
Exampleexample.com / example.org / example.net.
Random (default)Pronounceable local part + randomly generated domain.

Network ​

MemberSignatureNotes
Ipv4Ipv4(float publicChance = 1.0f)
Ipv6Ipv6(float publicChance = 1.0f)
IpAddressIpAddress(float publicChance = 1.0f, float ipv6Chance = 0.45f)IPv4 or IPv6.
PortPort(float wellKnownChance = 0.0f)1–65535.
EndpointEndpoint(float ipv6Chance = 0.45f, float publicChance = 1.0f, float wellKnownPortChance = 0.0f)IPEndPoint; plus Ipv4Endpoint / Ipv6Endpoint shortcuts.
UriSchemeUriScheme(bool strip = false)
MacAddressMacAddress(float locallyAdministeredChance = 0.0f)PhysicalAddress.

Finance ​

MemberSignatureNotes
CurrencyCurrency()Alias of CurrencyName().
CurrencyCode / CurrencyName / CurrencySymbol / CurrencyNumericCode—ISO 4217 projections.
IbanIban(bool valid = true, bool test = false) or Iban(string countryCode, ...)Valid mod-97 check digit unless valid: false; test: true returns a known test IBAN.
Bic / SwiftBic(bool valid = true, bool test = false)8- or 11-char SWIFT/BIC.
RoutingNumberRoutingNumber(bool valid = true, bool test = false)ABA 9-digit, mod-10 checksum.
AccountNumberAccountNumber(int length = 8) or AccountNumber(int minLength, int maxLength)Digits only.
CardOperatorCardOperator()A single CardOperator flag value.
CreditCardNumberCreditCardNumber(CardOperatorFlag cardOperator = All, bool valid = true, bool test = false)Luhn-valid unless valid: false.
CreditCardCvv / Cvv / CvcCreditCardCvv(CardOperatorFlag cardOperator = All)3- or 4-digit, network-dependent.
CreditCardExpirationDate / ExpirationDateCreditCardExpirationDate(DateTimeOffset? today = null, float expirationChance = 0.5f)First of month; ~50% already expired by default.

CardOperator is defined in the Forged.Core.Generators.Finance namespace.

Person ​

MemberSignatureNotes
FirstNameFirstName(float male = 0.5f, float female = 0.5f)
LastNameLastName(float hyphenated = 0.04f, float compound = 0.02f)
NamePrefixNamePrefix()Dr., Mr., …
NameInfixNameInfix()van, de, …
NameSuffixNameSuffix()Jr., Sr., …
FullNameFullName(float male = 0.5f, float female = 0.5f, float middle = 0.8f, float hyphenated = 0.04f, float compound = 0.02f, float prefix = 0f, float infix = 0.03f, float suffix = 0.04f)Composes parts by probability.

All person data comes from locale files, so FirstName, LastName, NamePrefix, NameInfix, NameSuffix and their compound full-name forms reflect the active locale's data set.