Skip to content

Mock

ClassMockMagiccom.wetzold.mock-magic
public static class Mock

Switch-style dispatcher from MockMagic.SimpleDataType to the matching generator. Lives in its own partial so the core file stays focused on the raw generators.

public static void RegisterToken(string name, Func<string> factory)

Register (or replace) a string-returning generator. The same name becomes usable as a {{name}} token inside MockMagic.Mock.Parse(System.String).

Parameters

Name Type
name System.String
factory System.Func{System.String}
public static void RegisterGenerator<T>(string name, Func<T> factory)

Register a typed generator. Works for any T. If T is System.String the generator also becomes a MockMagic.Mock.Parse(System.String) token.

Parameters

Name Type
name System.String
factory System.Func{{T}}
public static T Get<T>(string name)

Resolve a previously registered typed generator. Throws if no generator was registered for the T/name combination.

Parameters

Name Type
name System.String

Returns

{T}

public static bool UnregisterToken(string name)

Remove a previously registered token/generator. Built-in tokens can also be removed this way if you want to override them with a newly registered one.

Parameters

Name Type
name System.String

Returns

System.Boolean

public static bool HasToken(string name)

Check whether a token has been registered.

Parameters

Name Type
name System.String

Returns

System.Boolean

public static string Parse(string template)

Replace every {{tokenName}} in template with the current output of the matching registered generator. Unknown tokens are left as-is so they can be easily spotted during debugging.

Parameters

Name Type
template System.String

Returns

System.String

Examples

Mock.Parse(“{{firstName}} <{{email}}> id={{unique}}”)

public static string[] Parse(string template, int count)

Parse template repeatedly, returning one string per iteration.

Parameters

Name Type
template System.String
count System.Int32

Returns

System.String[]

public static string HackerAdjective()

Random tech-flavoured adjective, e.g. “cross-platform”.

Returns

System.String

public static string HackerNoun()

Random tech-flavoured noun, e.g. “firewall”.

Returns

System.String

public static string HackerVerb()

Random tech-flavoured verb (imperative), e.g. “bypass”.

Returns

System.String

public static string HackerIngVerb()

Random tech-flavoured verb in -ing form, e.g. “bypassing”.

Returns

System.String

public static string HackerPhrase()

Assemble a phrase like “try parsing the SSL sensor, maybe it will reboot the digital bus!”.

Returns

System.String

public static string Guid()

Generate a random GUID string. When a seed is active the GUID is produced from MockMagic.MockRandom so the output is reproducible; otherwise the runtime’s System.Guid.NewGuid is used for uniqueness guarantees.

Returns

System.String

public static string[] Guids(int count)

Generate multiple random GUIDs.

Parameters

Name Type
count System.Int32

Returns

System.String[]

public static int Id()

Generate a sequential ID using the shared MockMagic.MockRandom.UniqueIndex.

Returns

System.Int32

public static int[] Ids(int count)

Generate multiple sequential IDs.

Parameters

Name Type
count System.Int32

Returns

System.Int32[]

public static void ResetIdCounter(int startValue = 1)

Reset the ID counter (and the shared unique-index counter) to the default start.

Parameters

Name Type
startValue System.Int32
public static void UseDateReference(DateTime? reference)

Set a fixed reference date for date/time generators. Pass null to restore wall-clock behaviour.

Parameters

Name Type
reference System.Nullable{System.DateTime}
public static void UseDateReference(Func<DateTime> provider)

Set a dynamic reference-date provider for date/time generators.

Parameters

Name Type
provider System.Func{System.DateTime}
public static long Timestamp()

Generate a Unix timestamp (reference time with random offset of up to a year in each direction).

Returns

System.Int64

public static long[] Timestamps(int count)

Generate multiple timestamps.

Parameters

Name Type
count System.Int32

Returns

System.Int64[]

public static string Date(int yearsBack = 5, int yearsForward = 1)

Generate a random date string.

Parameters

Name Type
yearsBack System.Int32
yearsForward System.Int32

Returns

System.String

public static string[] Dates(int count, int yearsBack = 5, int yearsForward = 1)

Generate multiple random dates.

Parameters

Name Type
count System.Int32
yearsBack System.Int32
yearsForward System.Int32

Returns

System.String[]

public static string Time()

Generate a random time string (HH:mm:ss).

Returns

System.String

public static string[] Times(int count)

Generate multiple random times.

Parameters

Name Type
count System.Int32

Returns

System.String[]

public static string DateTime(int yearsBack = 5, int yearsForward = 1)

Generate a random datetime string.

Parameters

Name Type
yearsBack System.Int32
yearsForward System.Int32

Returns

System.String

public static string[] DateTimes(int count, int yearsBack = 5, int yearsForward = 1)

Generate multiple random datetimes.

Parameters

Name Type
count System.Int32
yearsBack System.Int32
yearsForward System.Int32

Returns

System.String[]

public static string Name()

Generate a random full name.

Returns

System.String

public static string[] Names(int count)

Generate multiple random names.

Parameters

Name Type
count System.Int32

Returns

System.String[]

public static string FirstName()

Generate a random first name.

Returns

System.String

public static string[] FirstNames(int count)

Generate multiple random first names.

Parameters

Name Type
count System.Int32

Returns

System.String[]

public static string LastName()

Generate a random last name.

Returns

System.String

public static string[] LastNames(int count)

Generate multiple random last names.

Parameters

Name Type
count System.Int32

Returns

System.String[]

public static string Email()

Generate a random email address.

Returns

System.String

public static string[] Emails(int count)

Generate multiple random emails.

Parameters

Name Type
count System.Int32

Returns

System.String[]

public static string Phone()

Generate a random phone number in the shape +1 (###) ###-####.

Returns

System.String

public static string[] Phones(int count)

Generate multiple random phone numbers.

Parameters

Name Type
count System.Int32

Returns

System.String[]

public static string Address()

Generate a random street address.

Returns

System.String

public static string[] Addresses(int count)

Generate multiple random addresses.

Parameters

Name Type
count System.Int32

Returns

System.String[]

public static string City()

Generate a random city name.

Returns

System.String

public static string[] Cities(int count)

Generate multiple random cities.

Parameters

Name Type
count System.Int32

Returns

System.String[]

public static string Country()

Generate a random country name.

Returns

System.String

public static string[] Countries(int count)

Generate multiple random countries.

Parameters

Name Type
count System.Int32

Returns

System.String[]

public static string ZipCode()

Generate a random 5-digit ZIP code.

Returns

System.String

public static string[] ZipCodes(int count)

Generate multiple random ZIP codes.

Parameters

Name Type
count System.Int32

Returns

System.String[]

public static string Company()

Generate a random company name.

Returns

System.String

public static string[] Companies(int count)

Generate multiple random company names.

Parameters

Name Type
count System.Int32

Returns

System.String[]

public static string JobTitle()

Generate a random job title.

Returns

System.String

public static string[] JobTitles(int count)

Generate multiple random job titles.

Parameters

Name Type
count System.Int32

Returns

System.String[]

public static string LoremIpsum(int wordCount = 50)

Generate lorem ipsum text.

Parameters

Name Type
wordCount System.Int32

Returns

System.String

public static string Word()

Generate a random word.

Returns

System.String

public static string[] Words(int count)

Generate multiple random words.

Parameters

Name Type
count System.Int32

Returns

System.String[]

public static string Sentence(int minWords = 5, int maxWords = 15)

Generate a random sentence.

Parameters

Name Type
minWords System.Int32
maxWords System.Int32

Returns

System.String

public static string[] Sentences(int count, int minWords = 5, int maxWords = 15)

Generate multiple random sentences.

Parameters

Name Type
count System.Int32
minWords System.Int32
maxWords System.Int32

Returns

System.String[]

public static string Paragraph(int sentenceCount = 5)

Generate a random paragraph.

Parameters

Name Type
sentenceCount System.Int32

Returns

System.String

public static string[] Paragraphs(int count, int sentenceCount = 5)

Generate multiple random paragraphs.

Parameters

Name Type
count System.Int32
sentenceCount System.Int32

Returns

System.String[]

public static Color Color()

Generate a random Unity Color.

Returns

UnityEngine.Color

public static Color[] Colors(int count)

Generate multiple random colors.

Parameters

Name Type
count System.Int32

Returns

UnityEngine.Color[]

public static string ColorName()

Generate a random color name.

Returns

System.String

public static string[] ColorNames(int count)

Generate multiple random color names.

Parameters

Name Type
count System.Int32

Returns

System.String[]

public static string HexColor()

Generate a random hex color string.

Returns

System.String

public static string[] HexColors(int count)

Generate multiple random hex colors.

Parameters

Name Type
count System.Int32

Returns

System.String[]

public static Vector2 Coordinate()

Generate a random coordinate (lat, lon).

Returns

UnityEngine.Vector2

public static Vector2[] Coordinates(int count)

Generate multiple random coordinates.

Parameters

Name Type
count System.Int32

Returns

UnityEngine.Vector2[]

public static float Latitude()

Generate a random latitude.

Returns

System.Single

public static float Longitude()

Generate a random longitude.

Returns

System.Single

public static decimal Currency(decimal min = 0, decimal max = 10000)

Generate a random currency amount.

Parameters

Name Type
min System.Decimal
max System.Decimal

Returns

System.Decimal

public static decimal[] Currencies(int count, decimal min = 0, decimal max = 10000)

Generate multiple random currency amounts.

Parameters

Name Type
count System.Int32
min System.Decimal
max System.Decimal

Returns

System.Decimal[]

public static float Percentage()

Generate a random percentage (0-100).

Returns

System.Single

public static float[] Percentages(int count)

Generate multiple random percentages.

Parameters

Name Type
count System.Int32

Returns

System.Single[]

public static bool Boolean()

Generate a random boolean.

Returns

System.Boolean

public static bool[] Booleans(int count)

Generate multiple random booleans.

Parameters

Name Type
count System.Int32

Returns

System.Boolean[]

public static int Integer(int min = 0, int max = 100)

Generate a random integer within range.

Parameters

Name Type
min System.Int32
max System.Int32

Returns

System.Int32

public static int[] Integers(int count, int min = 0, int max = 100)

Generate multiple random integers.

Parameters

Name Type
count System.Int32
min System.Int32
max System.Int32

Returns

System.Int32[]

public static float Float(float min = 0, float max = 100)

Generate a random float within range.

Parameters

Name Type
min System.Single
max System.Single

Returns

System.Single

public static float[] Floats(int count, float min = 0, float max = 100)

Generate multiple random floats.

Parameters

Name Type
count System.Int32
min System.Single
max System.Single

Returns

System.Single[]

public static string Url()

Generate a random URL.

Returns

System.String

public static string[] Urls(int count)

Generate multiple random URLs.

Parameters

Name Type
count System.Int32

Returns

System.String[]

public static string IpAddress()

Generate a random IP address.

Returns

System.String

public static string[] IpAddresses(int count)

Generate multiple random IP addresses.

Parameters

Name Type
count System.Int32

Returns

System.String[]

public static string MacAddress()

Generate a random MAC address (uppercase hex, colon-separated).

Returns

System.String

public static string[] MacAddresses(int count)

Generate multiple random MAC addresses.

Parameters

Name Type
count System.Int32

Returns

System.String[]

public static string Username()

Generate a random username.

Returns

System.String

public static string[] Usernames(int count)

Generate multiple random usernames.

Parameters

Name Type
count System.Int32

Returns

System.String[]

public static string Password(int length = 12)

Generate a random password with guaranteed character diversity.

Parameters

Name Type
length System.Int32

Returns

System.String

public static string[] Passwords(int count, int length = 12)

Generate multiple random passwords.

Parameters

Name Type
count System.Int32
length System.Int32

Returns

System.String[]

public static string CreditCard()

Generate a random credit card number with valid Luhn checksum (fake, for testing only).

Returns

System.String

public static string[] CreditCards(int count)

Generate multiple random credit card numbers.

Parameters

Name Type
count System.Int32

Returns

System.String[]

public static string Ssn()

Generate a random SSN-shaped string (fake, for testing only).

Returns

System.String

public static string[] Ssns(int count)

Generate multiple random SSNs.

Parameters

Name Type
count System.Int32

Returns

System.String[]

public static string Isbn()

Generate a random ISBN-13 with valid check digit.

Returns

System.String

public static string[] Isbns(int count)

Generate multiple random ISBNs.

Parameters

Name Type
count System.Int32

Returns

System.String[]

public static string State()

Generate a random US state name.

Returns

System.String

public static string[] States(int count)

Generate multiple random US state names.

Parameters

Name Type
count System.Int32

Returns

System.String[]

public static string Domain()

Generate a random domain name (e.g., “cloudpulse.io”).

Returns

System.String

public static string[] DomainNames(int count)

Generate multiple random domain names.

Parameters

Name Type
count System.Int32

Returns

System.String[]

public static string FullAddress()

Generate a random full address (e.g., “1234 Oak Ave, Seattle, WA 98101”).

Returns

System.String

public static string[] FullAddresses(int count)

Generate multiple random full addresses.

Parameters

Name Type
count System.Int32

Returns

System.String[]

public static int Age()

Generate a realistic adult age drawn from a Gaussian distribution (mean 38, stddev 14), clamped to the range 18-85.

Returns

System.Int32

public static int[] Ages(int count)

Generate multiple random ages.

Parameters

Name Type
count System.Int32

Returns

System.Int32[]

public static string ProductName()

Generate a random product name (e.g., “Ultra Wireless Headphones”).

Returns

System.String

public static string[] ProductNames(int count)

Generate multiple random product names.

Parameters

Name Type
count System.Int32

Returns

System.String[]

public static string Price(float min = 0.99, float max = 999.99)

Generate a random price string (e.g., “$49.99”).

Parameters

Name Type
min System.Single
max System.Single

Returns

System.String

public static string[] Prices(int count, float min = 0.99, float max = 999.99)

Generate multiple random prices.

Parameters

Name Type
count System.Int32
min System.Single
max System.Single

Returns

System.String[]

public static float StarRating()

Generate a random star rating (1.0-5.0 with realistic distribution skewed toward 3.5-4.5).

Returns

System.Single

public static float[] StarRatings(int count)

Generate multiple random star ratings.

Parameters

Name Type
count System.Int32

Returns

System.Single[]

public static string VersionNumber()

Generate a random semantic version number (e.g., “2.4.1”).

Returns

System.String

public static string[] VersionNumbers(int count)

Generate multiple random version numbers.

Parameters

Name Type
count System.Int32

Returns

System.String[]

public static string FileName()

Generate a random file name with extension (e.g., “report_2024.pdf”).

Returns

System.String

public static string[] FileNames(int count)

Generate multiple random file names.

Parameters

Name Type
count System.Int32

Returns

System.String[]

public static string UserAgent()

Generate a random browser user agent string.

Returns

System.String

public static string[] UserAgents(int count)

Generate multiple random user agent strings.

Parameters

Name Type
count System.Int32

Returns

System.String[]

public static string Animal()

Generate a random animal name.

Returns

System.String

public static string[] Animals(int count)

Generate multiple random animal names.

Parameters

Name Type
count System.Int32

Returns

System.String[]

public static string Hashtag()

Generate a random hashtag (e.g., “#gamedev”).

Returns

System.String

public static string[] Hashtags(int count)

Generate multiple random hashtags.

Parameters

Name Type
count System.Int32

Returns

System.String[]

public static string Honorific()

Generate a random honorific (e.g., “Dr.”, “Mr.”).

Returns

System.String

public static string[] Honorifics(int count)

Generate multiple random honorifics.

Parameters

Name Type
count System.Int32

Returns

System.String[]

public static string Emoji()

Generate a random emoji character.

Returns

System.String

public static string[] Emojis(int count)

Generate multiple random emojis.

Parameters

Name Type
count System.Int32

Returns

System.String[]

public static T Enum<T>() where T : Enum

Generate a random enum value.

Returns

{T}

public static T[] Enums<T>(int count) where T : Enum

Generate multiple random enum values.

Parameters

Name Type
count System.Int32

Returns

{T}[]

public static string Generate(SimpleDataType type)

Generate a single value of the specified type.

Parameters

Name Type
type MockMagic.SimpleDataType

Returns

System.String

public static string[] Generate(SimpleDataType type, int count)

Generate multiple values of the specified type.

Parameters

Name Type
type MockMagic.SimpleDataType
count System.Int32

Returns

System.String[]

public static void Seed(int seed)

Seed all MockMagic randomness for reproducible output. Equivalent to MockMagic.MockRandom.Seed(System.Int32).

Parameters

Name Type
seed System.Int32
public static void ResetSeed()

Clear the seed and restore default behaviour.

public static T Pick<T>(params T[] items)

Pick a random element from an array.

Parameters

Name Type
items {T}[]

Returns

{T}

PickWeighted(params (float weight, T value)[])

Section titled “PickWeighted(params (float weight, T value)[])”
public static T PickWeighted<T>(params (float weight, T value)[] items)

Pick a random element biased by weights.

Parameters

Name Type
items System.ValueTuple{System.Single,{T}}[]

Returns

{T}

public static void Shuffle<T>(IList<T> items)

Shuffle a list in place.

Parameters

Name Type
items System.Collections.Generic.IList{{T}}
public static T[] Subset<T>(T[] items, int count)

Return a random subset of unique items from an array.

Parameters

Name Type
items {T}[]
count System.Int32

Returns

{T}[]

public static string ImageUrl(int width = 640, int height = 480)

Random picsum.photos URL for the requested dimensions.

Parameters

Name Type
width System.Int32
height System.Int32

Returns

System.String

PlaceholderImageUrl(int, int, string, string, string)

Section titled “PlaceholderImageUrl(int, int, string, string, string)”
public static string PlaceholderImageUrl(int width = 640, int height = 480, string bg = null, string fg = null, string text = null)

placehold.co URL with optional background, foreground, and label.

Parameters

Name Type
width System.Int32
height System.Int32
bg System.String
fg System.String
text System.String

Returns

System.String

public static string SvgDataUri(int width = 640, int height = 480, Color? fill = null, string label = null)

Self-contained SVG data URI — useful when you need an offline placeholder asset.

Parameters

Name Type
width System.Int32
height System.Int32
fill System.Nullable{UnityEngine.Color}
label System.String

Returns

System.String

public static string Format(string pattern)

Replace symbols in pattern:

  • # → digit 0-9
  • ? → lowercase letter
  • * → digit or lowercase letter
  • \ → escape the next character (emit it literally)

Any other character is copied verbatim.

Parameters

Name Type
pattern System.String

Returns

System.String

Examples

Mock.Format(“###-##-####”)“123-45-6789”

public static string Hash(int length = 40, bool upperCase = false)

Random hexadecimal string (default 40 chars == SHA-1 length).

Parameters

Name Type
length System.Int32
upperCase System.Boolean

Returns

System.String

public static string Hexadecimal(int length, bool upperCase = false)

Random hexadecimal string of the requested length.

Parameters

Name Type
length System.Int32
upperCase System.Boolean

Returns

System.String

public static string AlphaNumeric(int length)

Random lowercase alphanumeric string (0-9, a-z).

Parameters

Name Type
length System.Int32

Returns

System.String

public static string Letters(int length, bool upperCase = false)

Random uppercase or mixed-case letter string of the requested length.

Parameters

Name Type
length System.Int32
upperCase System.Boolean

Returns

System.String

public static string ClampString(string value, int min, int max)

Truncate or pad value so its length falls in [min, max]. Padding uses lowercase letters.

Parameters

Name Type
value System.String
min System.Int32
max System.Int32

Returns

System.String

public static string Review(int minWords = 8, int maxWords = 30)

Build a short product-style review. minWords and maxWords hint at the desired length — the result rarely strays outside the range.

Parameters

Name Type
minWords System.Int32
maxWords System.Int32

Returns

System.String