# Random Generator Unity Asset

- Link: https://saguiitay.com/unity/random-generator/
- Published: 2018-06-08T07:51:49+03:00
- Author: Itay

## Overview

Random Generator is a utility library that allows you to easily add random names
to your game. The library includes a large variety of random generators, including:

 * City Names
 * Fantasy Names (for various races – dragon-born, dwarfs, elves, gnomes, goblins,
   halflings, human and orcs)
 * Modern Names (for various nationalities – American, Dutch, French, German, Icelandic,
   Indian, Irish, Italian, Japanese, Russian, Spanish and Swedish)
 * Planet / Constellation Names

The library is easily customizable:

 * You can add move flavors (races, nationalities, etc.)
 * Variations (First/Last name, etc.)
 * Randomizers (Selector and Markov are already included)
 * Customize existing generators (raw data is available in the source code)

**[Purchase Random Generator from the Unity Assets Store here >>](https://assetstore.unity.com/packages/slug/118768?aid=1101lS3S)**

## Screenshots

![Random Generator Screenshot 1](https://i0.wp.com/www.saguiitay.com/wp-content/
uploads/Screenshot1-19.png?ssl=1 "Random Generator Unity Asset 1")

![Random Generator Screenshot 2](https://i0.wp.com/www.saguiitay.com/wp-content/
uploads/Screenshot2-19.png?ssl=1 "Random Generator Unity Asset 2")

![Random Generator Screenshot 3](https://i0.wp.com/www.saguiitay.com/wp-content/
uploads/Screenshot3-18.png?ssl=1 "Random Generator Unity Asset 3")

## How to use Random Generator

### Add a Definition class to your scripts

Add the relevant Definition class to your script, along with a Random class:

    ```wp-block-preformatted
    private CityNameGenerator generator = new CityNameGenerator();
    private System.Random m_random;
    ```

### Generate random values

In your code, add the following snippet to generate a new random value:

    ```wp-block-preformatted
    generator.Generate(m_random);
    ```

## FAQ

### How do I generate specific values?

Each generator provides 2 properties – SupportedTypes and DefinitionFormats:

#### SupportedTypes

Supported types can be used to select a subset, or less generic value. For example,
when generating the names of a person, the supported types might be Male or Female.
When generating a name of a Fantasy character, you can choose the Race (e.g. Elf,
Dwarf, Orc) of the character.

#### DefinitionFormats

DefinitionFormats can be used to select a specific structure for the value. For 
example, when generating a name, you can choose between “FirstName LastName” and
just “FirstName”.

### How can I create a custom Generator?

The simplest way to do so would be to start with an existing Generator and customize
it to your need. I suggest you start with the CityNameGenerator class – it has the
following implementation details:

 * Supports multiple folders (for different nationalities)
 * Supports multiple DefinitionFormats
 * Contains both Item and Markov PartDefinitions

### What are PartDefinitions you ask?

Each generated value is created from one or more part (as defined in the selected
DefinitionFormat). Each part is created from a PartDefinition. A PartDefinition 
can be based on a list of predefined values, one of which will be randomly selected.
Alternatively, a PartDefinition can be based on a Markov model – a prediction-based
data structure that generate random values by sampling a list of known values.
