I changed the script to test on 200 strings at once and added some characters to the alphabet, which is more like a realistic scenario.
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class CheckForCollisions : MonoBehaviour {
string[] alphabet = {
"a","b","c","d","e","f","g","h","i","j","k","l","m",
"n","o","p","q","r","s","t","u","v","w","x","y","z",
"0","1","2","3","4","5","6","7","8","9","_","."
};
string[] randomNames = new string[200];
int[] randomNamesHashes = new int[200];
int iterations = 0;
IEnumerator Start () {
StartCoroutine(UpdateState_Iterations());
while (true) {
RandomNames_Setup();
SetHashes();
CheckForCollisions_();
iterations++;
yield return null;
}
}
IEnumerator UpdateState_Iterations () {
YieldInstruction wait1 = new WaitForSeconds(60.0f);
while (true) {
Debug.Log("200 done: " + iterations.ToString());
yield return wait1;
}
}
void RandomNames_Setup () {
for (int i = 0; i < randomNames.Length; i++) {randomNames[i] = "";};
int nameLength = 0;
int letterNumber = 0;
for (int i = 0; i < randomNames.Length; i++) {
nameLength = Random.Range(5,20);
for (int j = 0; j < nameLength; j++) {
letterNumber = Random.Range(0,alphabet.Length);
randomNames[i] += alphabet[letterNumber];
}
}
for (int i = 0; i < randomNames.Length; i++) {
for (int j = 0; j < randomNames.Length; j++) {
if (randomNames[i] == randomNames[j]) {
if (i != j) {
Debug.Log("NAMES DOUBLE");
}
}
}
}
}
void SetHashes () {
for (int i = 0; i < randomNamesHashes.Length; i++) {
randomNamesHashes[i] = Animator.StringToHash(randomNames[i]);
}
}
void CheckForCollisions_ () {
for (int i = 0; i < randomNamesHashes.Length; i++) {
for (int j = 0; j < randomNamesHashes.Length; j++) {
if (randomNamesHashes[i] == randomNamesHashes[j]) {
if (i != j) {
Debug.Log("COLLISION");
}
}
}
}
}
}
I have to go now, but I will probably let this run tomorrow for some time.
Maybe even for Shader.PropertyToID.