Skip to content

Guide 1.1.1꞉ Tailoring Characters

kesac edited this page Dec 1, 2023 · 1 revision

Quick Customization

Use the NameGenerator class to generate names. For simple generators, you can supply the vowels and consonants to use through the constructor.

using Syllabore;

public class Program
{
    public static void Main(string[] args)
    {
        var g = new NameGenerator("ae","strml");
        Console.WriteLine(g.Next());
    }
}

Each call to Next() will return names like:

Lena
Salna
Rasse

This way of NameGenerator customization is convenient, but limited. For more granular control, you will want to configure SyllableGenerators directly.

Basic Concepts

  • A SyllableGenerator is responsible for creating syllables
  • A NameGenerator is responsible for creating names
  • A NameGenerator uses a SyllableGenerator internally

To tailor characters used in name generation, supply a SyllableGenerator to your NameGenerator:

var s = new SyllableGenerator()
        .WithVowels("ae")          // Future syllables will only use these vowels
        .WithConsonants("strmnl"); // Future syllables will only use these consonants

var g = new NameGenerator(s);     

Names from this generator will only ever have the characters a and e for vowels, and the characters s t r m n and l for consonants.

You can also express this in a more compact way like so:

var g = new NameGenerator()
        .UsingSyllables(x => x 
            .WithVowels("ae")
            .WithConsonants("strmnl"));     

Like the example in the Quick Customization section, calling Next() on this generator will produce names like:

Lena
Salna
Rasse