string _NextName() { //get a random token somewhere in middle of sample word string s = ""; var count = 0; do { count++; if (count > 15) { suffix++; } int n = (Rnd.Range(0, _samples.Count)); int nameLength = UnityEngine.Mathf.Min(_samples [n].Length, 12); s = _samples [n].Substring((Rnd.Range(0, _samples [n].Length - _order)), _order); while (s.Length < nameLength) { string token = s.Substring(s.Length - _order, _order); char c = GetLetter(token); if (c != '?') { s += GetLetter(token); } else { break; } } if (s.Contains(" ")) { string[] tokens = s.Split(' '); s = ""; for (int t = 0; t < tokens.Length; t++) { if (tokens [t] == "") { continue; } if (tokens [t].Length == 1) { tokens [t] = tokens [t].ToUpper(); } else { tokens [t] = tokens [t].Substring(0, 1) + tokens [t].Substring(1).ToLower(); } if (s != "") { s += " "; } s += tokens [t]; } } else { s = s.Substring(0, 1) + s.Substring(1).ToLower(); } if (suffix > 0) { s += "-" + ToRoman(suffix + 1); } } while (_used.Contains(s) || s.Length < _minLength); _used.Add(s); return(s); }
/// <summary> /// Get a random element from the list. /// </summary> /// <returns> /// A <see cref="T"/> /// </returns> public static T GetRandom <T> (this IList <T> list) { return(list [Rnd.Range(0, list.Count)]); }