Пример #1
0
        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);
        }
Пример #2
0
        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);
        }
Пример #3
0
 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)]);
 }
Пример #4
0
        public int Seed(string key = null)
        {
            int num;

            if (string.IsNullOrEmpty(key))
            {
                this.last = (this.a * this.last + this.c) % this.m;
                num       = this.last;
            }
            else
            {
                num = this.seed + URandom.GetCode(key);
            }
            return((this.a * num + this.c) % this.m);
        }
Пример #5
0
        public float Value(string key = null)
        {
            int num;

            if (string.IsNullOrEmpty(key))
            {
                this.last = (this.a * this.last + this.c) % this.m;
                num       = this.last;
            }
            else
            {
                num = this.seed + URandom.GetCode(key);
            }
            return(Math.Abs(1f * (float)(this.a * num + this.c) % (float)this.m / (float)this.m));
        }