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

Code before:
                output.X = NextFloat(random) * 2.0f - 1.0f;
                output.Y = NextFloat(random) * 2.0f - 1.0f;

            } while (output.LengthSquared > 1 || output.LengthSquared < 1e-6f);

            output *= (1.0f / (float)Math.Sqrt(output.LengthSquared));

            return output;
        }

        /// <summary>
        /// Generates a random <see cref="Color"/>.
        /// </summary>
        /// <param name="random">An instance of <see cref="Random"/>.</param>
        /// <param name="trueRandom">Should the color be generated from a single random Hue value or separate values for each channel.</param>
        /// <param name="randomAlpha">Randomize the alpha value.</param>
        /// <returns>A nice random <see cref="Color"/>.</returns>
        public static Color NextColor(this Random random, bool trueRandom, bool randomAlpha)
        {
            float alpha = randomAlpha ? NextFloat(random) : 1f;

            if (!trueRandom)
                return Color.FromHSV(NextFloat(random, 0f, 360f), 1f, 1f, alpha);

            return new Color(
                NextFloat(random, 0f, 255f),
                NextFloat(random, 0f, 255f),
                NextFloat(random, 0f, 255f), alpha);
        }

        /// <summary>
        /// Gets a random <see cref="double"/>.
        /// </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="double"/>.</returns>
        public static double NextDouble(this Random random, double min = 0.0d, double max = 2.0d)
        {
            return random.NextDouble() * (max - min) + min;
        }

        /// <summary>
        /// Gets a random <see cref="long"/>.
        /// </summary>
        /// <param name="random">An instance of <see cref="Random"/>.</param>
        /// <returns>A random <see cref="long"/>.</returns>
        internal static long NextLong(this Random random)
        {
            var numArray = new byte[8];
            random.NextBytes(numArray);

Review comment (suggestion):
Please use `NextFloat(random)` here. Colors have float values in the range 0.0 to 1.0.

Code after:
                output.Y = NextFloat(random) * 2.0f - 1.0f;
                output.Z = NextFloat(random) * 2.0f - 1.0f;

                l = output.LengthSquared;

            } while (l > 1 || l < Mathf.Epsilon);

            output.Normalize();

            return output;
        }

        /// <summary>
        /// Gets a random <see cref="Vector2"/> with components in a given range.
        /// </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="Vector2"/>.</returns>
        public static Vector2 NextVector2(this Random random, float min = 0.0f, float max = 1.0f)
        {
            return new Vector2 
            {
                X = NextFloat(random, min, max), 
                Y = NextFloat(random, min, max)
            };
        }

        /// <summary>
        /// Gets a random <see cref="Vector3"/> with components in a given range.
        /// </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="Vector3"/>.</returns>
        public static Vector3 NextVector3(this Random random, float min = 0.0f, float max = 1.0f)
        {
            return new Vector3
            {
                X = NextFloat(random, min, max),
                Y = NextFloat(random, min, max),
                Z = NextFloat(random, min, max)
            };
        }

        /// <summary>
        /// Gets a random <see cref="Vector4"/> with components in a given range.
        /// </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>