Exemple #1
0
        string WeightedNameFormat()
        {
            NameSettings settings = new NameSettings();
            Random       rnd      = new Random();

            int    weights       = 0;
            string selection     = "";
            int    randSelection = rnd.Next(settings.formatWeights.Count);

            foreach (KeyValuePair <string, int> format in settings.formatWeights)
            {
                if (randSelection < format.Value + weights)
                {
                    selection = format.Key;
                    break;
                }
                else
                {
                    weights += format.Value;
                }
            }

            return(selection);
        }
Exemple #2
0
        public string GetName()
        {
            Random       rnd      = new Random();
            NameSettings settings = new NameSettings();
            string       format   = WeightedNameFormat();
            string       name     = "";

            if (format == "English" ||
                format == "Japanese")   // Full Name Generator
            {
                List <string> firstNames = Localisations(format, true);
                List <string> lastNames  = Localisations(format, false);

                name = string.Join(" ", firstNames[rnd.Next(firstNames.Count)], lastNames[rnd.Next(lastNames.Count)]);
            }
            else if (format == "Japanese Syllables")   // Japanese Name Generator
            {
                int[] syllableCounts = settings.formatSyllables[format];

                int firstNameSyllableCount = rnd.Next(syllableCounts[0], syllableCounts[1] + 1);
                int lastNameSyllableCount  = rnd.Next(syllableCounts[2], syllableCounts[3] + 1);

                string firstName = "";
                string lastName  = "";

                for (int i = 0; i < firstNameSyllableCount; i++)
                {
                    firstName += JapaneseSyllables[rnd.Next(JapaneseSyllables.Count)];
                }
                firstName = char.ToUpper(firstName[0]) + firstName.Substring(1);

                for (int i = 0; i < lastNameSyllableCount; i++)
                {
                    lastName += JapaneseSyllables[rnd.Next(JapaneseSyllables.Count)];
                }
                lastName = char.ToUpper(lastName[0]) + lastName.Substring(1);

                name = string.Concat(firstName, " ", lastName);
            }
            else if (format == "Chinese Syllables")
            {
                int[] syllableCounts = settings.formatSyllables[format];

                int firstNameSyllableCount = rnd.Next(syllableCounts[0], syllableCounts[1] + 1);
                int lastNameSyllableCount  = rnd.Next(syllableCounts[2], syllableCounts[3] + 1);

                string firstName = "";
                string lastName  = "";

                for (int i = 0; i < firstNameSyllableCount; i++)
                {
                    firstName += ChineseSyllables[rnd.Next(ChineseSyllables.Count)];
                }
                firstName = char.ToUpper(firstName[0]) + firstName.Substring(1);

                for (int i = 0; i < lastNameSyllableCount; i++)
                {
                    lastName += ChineseSyllables[rnd.Next(ChineseSyllables.Count)];
                }
                lastName = char.ToUpper(lastName[0]) + lastName.Substring(1);

                name = string.Concat(firstName, " ", lastName); return(name);
            }

            // Suffix?
            if (rnd.NextDouble() < settings.probabilitySuffix)
            {
                name = string.Join(", ", name, nameSuffix[rnd.Next(nameSuffix.Count)]);
            }


            return(name);
        }