Class RandomNameGenerator
- All Implemented Interfaces:
Serializable
Files are located in /data/names/. All files are comma spaced csv files
The historicalEthnicity.csv file shows the correspondence between the different ethnic names and their numeric code in the database. This file is used to initialize the name mapping, and must be kept current for all additions. The same numeric code MUST be used across all of the files listed below. The numeric codes MUST be listed in exact sequential order (NO skipped numbers) for the load to work correctly.
The name database is located in three files: maleGivenNames.csv, femaleGivenNames.csv, and surnames.csv.
The database is divided into three fields; an Integer Ethnic Code, a String name, and an Integer weight.
The Ethnic Code is an Integer identifying the ethnic group from the historicalEthnicity.csv file the name is from
The Name is a String containing either a male/female first name or a surname, dependent on the origin file.
The Weight is an Integer that is used to set the generation chance of the name. The higher the number, the more common the name is.
Faction files are located in /data/names/factions/ directory. The faction key is the filename without the extension. The faction files will have varying number of fields depending on how many ethnic groups exist. The faction file does two things:
First, it identifies the relative frequency of different ethnic surnames for a faction.
Second, it identifies the correspondence between first names and surnames.
This allows, for example, for more Japanese first names regardless of surname in the Draconis Combine. There MUST be a line in the Faction file for each ethnic group, although a weight of 0 can be used to prevent the generation of a grouping of names
This is divided into 3 + n fields, where n is the number of ethnic groups listed in historicalEthnicity.csv, divided into the following groupings:
The Integer Ethnic Code is the first field
The String Ethnic Name is the second field. This is included for ease of reference, and is NOT used by the generator.
The Integer Weight for generating a surname of the specified ethnicity. The higher the number, the more common the surname is for a faction.
This is followed by n fields each containing the Integer Weight for generating a given name for the ethnicity with Ethnic Code n. The higher the number for the weight, the more common that given name ethnicity is in generation for the specific ethnicity of the generated surname.
- See Also:
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionThis is used to generate a name for MegaMek only that uses the chosen factionGenerate a single random name for MegaMek onlyString[]generateGivenNameSurnameSplit(Gender gender, boolean clanPilot, String faction) Generate a single random name split between a given name and surnameString[]generateGivenNameSurnameSplitWithEthnicCode(Gender gender, boolean clanPilot, int ethnicCode) generateWithEthnicCode(Gender gender, boolean clanPilot, int ethnicCode) static RandomNameGeneratorvoidsetChosenFaction(String chosenFaction)
-
Field Details
-
KEY_DEFAULT_FACTION
- See Also:
-
KEY_DEFAULT_CLAN
- See Also:
-
UNNAMED
- See Also:
-
UNNAMED_SURNAME
- See Also:
-
UNNAMED_FULL_NAME
- See Also:
-
-
Constructor Details
-
RandomNameGenerator
public RandomNameGenerator()
-
-
Method Details
-
generate
This is used to generate a name for MegaMek only that uses the chosen faction- Parameters:
gender- the gender to generate the name forclanPilot- if the name is for a clanPilot- Returns:
- a string containing the randomly generated name
-
generate
Generate a single random name for MegaMek only- Parameters:
gender- the gender to generate the name forclanPilot- if the name is for a clanPilotfaction- a string containing the faction key with which to generate the name from. If the faction is not a key for thefactionSurnamesMap, it will instead generate based on the General list- Returns:
- a string containing the randomly generated name
-
generateWithEthnicCode
- Parameters:
gender- the gender to generate the name forclanPilot- if the person is a clanPilotethnicCode- the specified ethnic code- Returns:
- a string containing the randomly generated name
-
generateGivenNameSurnameSplit
Generate a single random name split between a given name and surname- Parameters:
gender- the gender to generate the name forclanPilot- if the person is a clanPilotfaction- a string containing the faction key with which to generate the name from. If the faction is not a key for thefactionSurnamesMap, it will instead generate based on the General list- Returns:
- - a String[] containing the name, with the given name at String[0] and the surname at String[1]
-
generateGivenNameSurnameSplitWithEthnicCode
public String[] generateGivenNameSurnameSplitWithEthnicCode(Gender gender, boolean clanPilot, int ethnicCode) - Parameters:
gender- the gender to generate the name forclanPilot- if the person is a clanPilotethnicCode- the specified ethnic code- Returns:
- - a String[] containing the name, with the given name at String[0] and the surname at String[1]
-
getFactions
- Returns:
- the set of potential keys to generate the name from - this MUST NOT be modified once it has been gotten
-
getChosenFaction
- Returns:
- the chosen faction to generate the name from
-
setChosenFaction
- Parameters:
chosenFaction- the faction to use to generate the name
-
getHistoricalEthnicity
- Returns:
- the historical ethnicity map
-
getInstance
- Returns:
- the instance of the RandomNameGenerator to use
-