Repository: FlaxEngine/FlaxEngine
File: Source/Engine/Utilities/Extensions.cs (C#)

Code before:
            while (n > 1)
            {
                n--;
                int k = random.Next(n + 1);
                T value = collection[k];
                collection[k] = collection[n];
                collection[n] = value;
            }
        }

        /// <summary>
        /// Generates a random <see cref="bool"/>.
        /// </summary>
        /// <param name="random">An instance of <see cref="Random"/>.</param>
        /// <param name="weight">Normalized value that determines the chance to return true.</param>
        /// <returns>A <see cref="bool"/> thats either true or false.</returns>
        public static bool NextBool(this Random random, float weight = 0.5f) => random.NextDouble() < weight;

        /// <summary>
        /// Generates a random <see cref="byte"/> value between min and max.
        /// </summary>
        /// <param name="random">An instance of <see cref="Random"/>.</param>
        /// <param name="min">The minimum value.</param>
        /// <param name="max">The maximum value.</param>
        /// <returns>A random <see cref="byte"/> between min and max.</returns>
        public static byte NextByte(this Random random, byte min = 0, byte max = byte.MaxValue)
        {
            return (byte)random.Next(min, max);
        }

        /// <summary>
        /// Generates a random <see cref="float"/> value between min and max.
        /// </summary>
        /// <param name="random">An instance of <see cref="Random"/>.</param>
        /// <param name="min">The minimum value.</param>
        /// <param name="max">The maximum value.</param>
        /// <returns>A random <see cref="float"/> between min and max.</returns>
        public static float NextFloat(this Random random, float min = 0.0f, float max = 1.0f)
        {
            return (float)random.NextDouble() * (max - min) + min;
        }

        /// <summary>
        /// Generates a random <see cref="float"/>  value between 0 and max.
        /// </summary>
        /// <param name="random">An instance of <see cref="Random"/>.</param>
        /// <param name="max">The maximum value.</param>
        /// <returns>A random <see cref="float"/> between min and max.</returns>
        public static float NextFloat(this Random random, float max)
        {
            return (float)random.NextDouble() * max;

Review comment (bug):
This is a sneaky off-by-one bug, since the maximum is exclusive. Meaning `random.Next(0, 255);` won't ever return 255.

Code after:
            while (n > 1)
            {
                n--;
                int k = random.Next(n + 1);
                T value = collection[k];
                collection[k] = collection[n];
                collection[n] = value;
            }
        }

        /// <summary>
        /// Generates a random <see cref="bool"/>.
        /// </summary>
        /// <param name="random">An instance of <see cref="Random"/>.</param>
        /// <param name="weight">Normalized value that determines the chance to return true.</param>
        /// <returns>A <see cref="bool"/> thats either true or false.</returns>
        public static bool NextBool(this Random random, float weight = 0.5f) => random.NextDouble() < weight;

        /// <summary>
        /// Generates a random <see cref="byte"/> value between min and max.
        /// </summary>
        /// <param name="random">An instance of <see cref="Random"/>.</param>
        /// <param name="min">The minimum value.</param>
        /// <param name="max">The maximum value.</param>
        /// <returns>A random <see cref="byte"/> between min and max.</returns>
        public static byte NextByte(this Random random, byte min = 0, byte max = byte.MaxValue)
        {
            return (byte)random.Next(min, max == byte.MaxValue ? byte.MaxValue + 1 : max);
        }

        /// <summary>
        /// Generates a random <see cref="float"/> value between min and max.
        /// </summary>
        /// <param name="random">An instance of <see cref="Random"/>.</param>
        /// <param name="min">The minimum value.</param>
        /// <param name="max">The maximum value.</param>
        /// <returns>A random <see cref="float"/> between min and max.</returns>
        public static float NextFloat(this Random random, float min = 0.0f, float max = 1.0f)
        {
            return (float)random.NextDouble() * (max - min) + min;
        }

        /// <summary>
        /// Generates a random <see cref="float"/>  value between 0 and max.
        /// </summary>
        /// <param name="random">An instance of <see cref="Random"/>.</param>
        /// <param name="max">The maximum value.</param>
        /// <returns>A random <see cref="float"/> between min and max.</returns>
        public static float NextFloat(this Random random, float max)
        {
            return (float)random.NextDouble() * max;