public static ICollection <T> Unsort <T>( this ICollection <T> collection, URandom random = null) { if (collection == null) { return((ICollection <T>)null); } int[] numArray = new int[collection.Count]; for (int index = 0; index < numArray.Length; ++index) { numArray[index] = index; } for (int max = numArray.Length - 1; max > 0; --max) { int index = random == null?UnityEngine.Random.Range(0, max) : random.Range(0, max - 1, (string)null); numArray[index] = numArray[index] + numArray[max]; numArray[max] = numArray[index] - numArray[max]; numArray[index] = numArray[index] - numArray[max]; } List <T> objList = new List <T>(); for (int index = 0; index < numArray.Length; ++index) { objList.Add(collection.ElementAt <T>(numArray[index])); } return((ICollection <T>)objList); }
public static Dictionary <N, M> Unsort <N, M>( this IDictionary <N, M> dictionary, URandom random = null) { if (dictionary == null) { return((Dictionary <N, M>)null); } int[] numArray = new int[dictionary.Count]; for (int index = 0; index < numArray.Length; ++index) { numArray[index] = index; } for (int max = numArray.Length - 1; max > 0; --max) { int index = random == null?UnityEngine.Random.Range(0, max) : random.Range(0, max - 1, (string)null); numArray[index] = numArray[index] + numArray[max]; numArray[max] = numArray[index] - numArray[max]; numArray[index] = numArray[index] - numArray[max]; } Dictionary <N, M> dictionary1 = new Dictionary <N, M>(); for (int index = 0; index < numArray.Length; ++index) { dictionary1.Add(dictionary.Keys.ElementAt <N>(numArray[index]), dictionary.Values.ElementAt <M>(numArray[index])); } return(dictionary1); }
public static T GetRandom <T>(this IEnumerable <T> collection, URandom random, string key = null) { if (collection == null) { return(default(T)); } T[] array = collection.ToArray <T>(); if (array.Length == 0) { return(default(T)); } return(array[random.Range(0, array.Length - 1, key)]); }