/// <summary>Fast random will only work if you are sure the dictonary is indexed like an array!</summary> public static T GetRandomObjectFromCollection <T>(Dictionary <int, T> thisDictionary, bool fastRandom = false) { int targetIndex = ThreadedRandom.Range(0, thisDictionary.Count); if (fastRandom) { return(thisDictionary[targetIndex]); } int currentIndex = 0; foreach (var thisPair in thisDictionary) { if (currentIndex == targetIndex) { return(thisPair.Value); } currentIndex++; } throw new Exception("This should not happen!"); }
public static T GetRandomObjectFromCollection <T>(List <T> thisList) => thisList[ThreadedRandom.Range(0, thisList.Count)];
public static T GetRandomObjectFromCollection <T>(T[] thisArray) => thisArray[ThreadedRandom.Range(0, thisArray.Length)];