<commit_before>﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Text.RegularExpressions;

public class StringManager : MonoBehaviour
{
	private static StringManager stringManager;
	public static StringManager Instance
	{
		get
		{
			if (stringManager == null)
			{
				stringManager = FindObjectOfType<StringManager>();
			}
			return stringManager;
		}
	}

	public Dictionary<string, List<string>> textObjects = new Dictionary<string, List<string>>();

	public List<TextAsset> nameTextFiles;

	void Start()
	{
		for (int i = 0; i < nameTextFiles.Count; i++)
		{
			string[] lines = Regex.Split(nameTextFiles[i].text, "\n|\r|\r\n");
			textObjects.Add(nameTextFiles[i].name, new List<string>(lines));
		}
	}

	public static string GetRandomMaleName(){
		var newName = Instance.textObjects["first_male"]
		[Random.Range(0,Instance.textObjects["first_male"].Count - 1)];
		newName += " " + Instance.textObjects["last"]
		[Random.Range(0,Instance.textObjects["last"].Count - 1)];
		return newName;
	}

	public static string GetRandomFemaleName(){
		var newName = Instance.textObjects["first_female"]
		[Random.Range(0,Instance.textObjects["first_female"].Count - 1)];
		newName += " " + Instance.textObjects["last"]
		[Random.Range(0,Instance.textObjects["last"].Count - 1)];
		return newName;
	}

}<commit_msg>Fix random name generation and slightly refactor it.<commit_after>﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class StringManager : MonoBehaviour
{
	private static StringManager stringManager;
	public static StringManager Instance
	{
		get
		{
			if (stringManager == null)
			{
				stringManager = FindObjectOfType<StringManager>();
			}
			return stringManager;
		}
	}

	public Dictionary<string, List<string>> textObjects = new Dictionary<string, List<string>>();

	public List<TextAsset> nameTextFiles;

	void Start()
	{
		for (int i = 0; i < nameTextFiles.Count; i++)
		{
			string[] lines = nameTextFiles[i].text.Split(
				new[] { "\r\n", "\r", "\n" },
				System.StringSplitOptions.None);
			textObjects.Add(nameTextFiles[i].name, new List<string>(lines));
		}
	}

	public static string GetRandomMaleName(){
		return GetRandomName(Gender.Male);
	}

	public static string GetRandomFemaleName(){
		return GetRandomName(Gender.Female);
	}

	/// <summary>
	/// Combines a random first and last name depending on gender, uses both male and female names if gender is Nueter
	/// </summary>
	public static string GetRandomName(Gender gender)
	{
		if (gender == Gender.Neuter) gender = Random.value > 0.5f ? Gender.Male : Gender.Female; //Uses random gendered name if Nueter
		var genderKey = gender.ToString().ToLowerInvariant(); //ToLowerInvariant because ToLower has different behaviour based on culture
		var firstName = Instance.textObjects[$"first_{genderKey}"][Random.Range(0, Instance.textObjects[$"first_{genderKey}"].Count)]; //Random.Range is max exclusive and as such .Count can be used directly
		var lastName  = Instance.textObjects["last"              ][Random.Range(0, Instance.textObjects["last"              ].Count)];
		return $"{firstName} {lastName}";
	}
}
{'fraction_non_alphanumeric': 0.13137996219281664, 'fraction_numerical': 0.004410838059231254, 'mean_word_length': 4.531358885017422, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 20, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4038717', 'n_tokens_mistral': 1061, 'n_tokens_neox': 955, 'n_words': 237}