Skip to content
m4bwav edited this page Sep 30, 2026 · 3 revisions

Install

In a project directory:

dotnet add package RandomNameGeneratorLibrary

Or add the reference to the project file yourself:

<PackageReference Include="RandomNameGeneratorLibrary" Version="2.3.0" />

In Visual Studio's Package Manager Console:

Install-Package RandomNameGeneratorLibrary

The package targets netstandard2.0 and net10.0, so it works on .NET Framework 4.6.2 and later, .NET Core, .NET 5 and later, Mono and Unity. It has no dependencies, so nothing else is added to your project. The download is 943 KB, almost all of it the name lists.

The first call

Every generator lives in the namespace RandomNameGeneratorLibrary. Each method name says what it does.

using System;
using RandomNameGeneratorLibrary;

var people = new PersonNameGenerator();
Console.WriteLine(people.GenerateRandomFirstAndLastName());  // "Jon Rohl"
Console.WriteLine(people.GenerateRandomFemaleFirstName());   // "Hildegard"
Console.WriteLine(people.GenerateRandomMaleFirstName());     // "Benny"
Console.WriteLine(people.GenerateRandomLastName());          // "Drouillard"

var places = new PlaceNameGenerator();
Console.WriteLine(places.GenerateRandomPlaceName());         // "Prophetstown"

var stars = new StarNameGenerator();
Console.WriteLine(stars.GenerateRandomStarName());           // "26 Vulpeculae"
Console.WriteLine(stars.GenerateRandomProperStarName());     // "Ankaa"
Console.WriteLine(stars.GenerateRandomCatalogStarName());    // "HD 107420"

The comments show one answer each; a generator made this way gives different names on every run.

Several at once

IEnumerable<string> five = people.GenerateMultipleFirstAndLastNames(5);
IEnumerable<string> towns = places.GenerateMultiplePlaceNames(3);

The GenerateMultiple... methods build the whole list before returning, so enumerating the result twice gives the same names. Zero gives an empty list. A negative count throws ArgumentOutOfRangeException.

The same names every run

Pass a seed to get the same sequence every time, on every runtime:

var people = new PersonNameGenerator(42);
Console.WriteLine(people.GenerateRandomFirstAndLastName());  // always "Alisa Streets"

var places = new PlaceNameGenerator(42);
Console.WriteLine(places.GenerateRandomPlaceName());         // always "Boardman"

Reproducible names explains what a seed does and does not fix.

From a Random you already have

The same methods exist as extension methods on System.Random:

var random = new Random(42);
Console.WriteLine(random.GenerateRandomFemaleFirstName());  // "Marguerita"
Console.WriteLine(random.GenerateRandomPlaceName());        // "Sedco Hills"
Console.WriteLine(random.GenerateRandomStarName());         // "Ran"

The three answers follow each other because the calls share one Random.

A script instead of a project

A .NET 10 file-based app needs one line for the package:

#:package RandomNameGeneratorLibrary@2.3.0
using System;
using RandomNameGeneratorLibrary;

Console.WriteLine(new PersonNameGenerator().GenerateRandomFirstAndLastName());
dotnet run names.cs

F# Interactive:

#r "nuget: RandomNameGeneratorLibrary, 2.3.0"
open System
open RandomNameGeneratorLibrary

let people = PersonNameGenerator(42)
printfn "%s" (people.GenerateRandomFirstAndLastName())   // Alisa Streets
printfn "%s" (Random(42).GenerateRandomPlaceName())      // Boardman

PowerShell 7 can load the assembly straight from the NuGet cache. The cache holds it once any project on the machine has restored the package; otherwise download the .nupkg from nuget.org and unzip it.

Add-Type -Path "$env:USERPROFILE/.nuget/packages/randomnamegeneratorlibrary/2.3.0/lib/netstandard2.0/RandomNameGeneratorLibrary.dll"
[RandomNameGeneratorLibrary.PersonNameGenerator]::new().GenerateRandomFirstAndLastName()
[RandomNameGeneratorLibrary.PlaceNameGenerator]::new(42).GenerateRandomPlaceName()   # Boardman
[RandomNameGeneratorLibrary.PersonNameGenerator]::LastNames.Count                     # 88799

Unity

Use the netstandard2.0 build. A .nupkg is a zip file: copy lib/netstandard2.0/RandomNameGeneratorLibrary.dll into Assets/Plugins, or install it with a NuGet-for-Unity tool. The library has no dependencies, no runtime regular expressions and no reflection beyond reading its own embedded resources. Seeded generators behave the same as anywhere else.

Accents and superscripts

Some names contain characters outside ASCII: 52 place names such as Mayagüez zona urbana, and star names such as Boötis, Rosalíadecastro or Delta² Gruis. If a Windows console shows them as question marks, set the console encoding first:

Console.OutputEncoding = System.Text.Encoding.UTF8;

Next: Recipes for working patterns, or the API reference for every method.

Clone this wiki locally