-
Notifications
You must be signed in to change notification settings - Fork 24
Getting Started
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.
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.
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.
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.
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 .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.csF# 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()) // BoardmanPowerShell 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 # 88799Use 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.
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.
This wiki describes RandomNameGeneratorLibrary 2.3.0 and was last updated on 2026-09-30. The library is MIT licensed. Report problems in the issues.