Ejemplo n.º 1
0
        /// <summary>
        /// Shuffle the collection.
        /// </summary>
        public static void Shuffle <T>(this IList <T> collection)
        {
            for (int i = collection.Count - 1; i >= 0; i--)
            {
                int randomIndex = MyRandom.Next(0, i + 1);

                T objInPosI = collection[i];

                collection[i]           = collection[randomIndex];
                collection[randomIndex] = objInPosI;
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        ///  Return true or false based on a probability of "0.0 to 1.0"
        /// </summary>
        public static bool Chance(float probability)
        {
            int randint = MyRandom.Next(0, 101);

            return((probability * 100) >= randint);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Choice and return a random value of the collection.
        /// </summary>
        public static T ChoiceAnyOne <T>(this IReadOnlyList <T> collection)
        {
            int index = MyRandom.Next(0, collection.Count);

            return(collection[index]);
        }