From 783b9107009384e8958a6a4a2a78577b333b5eb5 Mon Sep 17 00:00:00 2001 From: "W2.Wizard" Date: Tue, 12 Jan 2021 20:29:32 +0100 Subject: [PATCH] Added XML comments --- Source/Engine/Core/Math/Randomf.cs | 94 +++++++++++++++++++++--------- 1 file changed, 67 insertions(+), 27 deletions(-) diff --git a/Source/Engine/Core/Math/Randomf.cs b/Source/Engine/Core/Math/Randomf.cs index 791de2cb8..9e25456ab 100644 --- a/Source/Engine/Core/Math/Randomf.cs +++ b/Source/Engine/Core/Math/Randomf.cs @@ -12,32 +12,44 @@ namespace FlaxEngine // Single instance for random private static Random _rand = new Random(0); + //TODO: Implement some form of generic method for numerics? + /// /// Sets the seed of the random number generator. - /// Causes to construct a new instance. + /// Constructs a new instance. /// - /// The new seed + /// The new seed. public static void SetSeed(int newSeed) => _rand = new Random(newSeed); - // Bool + /// + /// Generates a random . + /// + /// A thats either true or false. + public static bool RandomBool() => RandomInt() == 1; - public static bool RandomBool() - { - return RandomInt() == 1 ? true : false; - } - - public static bool RandomBoolWithWeight(float weight = 0) - { - return weight >= RandomInt() ? true : false; - } - - // Byte + /// + /// Generates a random with a weight value to adjust preference. + /// + /// Normalized value that determines the chance to return true. + /// A thats either true or false. + public static bool RandomBoolWithWeight(float weight = 0) => weight >= RandomFloat(); + /// + /// Generates a random value between min and max. + /// + /// The lower boundary. + /// The upper boundary. + /// A between min and max. public static byte RandomByte(byte min = 0, byte max = 1) { return (byte)_rand.Next(min, max+1); } + /// + /// Generates a random by using a single value as both upper and lower boundary. + /// + /// Defines both upper and lower boundary. + /// A that is between +value and -value. public static byte RandomUniformByte(byte value = 1) { int max = Math.Abs(value); @@ -46,13 +58,22 @@ namespace FlaxEngine return (byte)_rand.Next(min, max); } - // Int - + /// + /// Generates a random value between min and max. + /// + /// The lower boundary. + /// The upper boundary. + /// A random between min and max. public static int RandomInt(int min = 0, int max = 1) { return _rand.Next(min, max+1); } + /// + /// Generates a random by using a single value as both upper and lower boundary. + /// + /// Defines both upper and lower boundary. + /// A random between +value and -value. public static int RandomUniformInt(int value = 1) { int max = Math.Abs(value); @@ -61,13 +82,22 @@ namespace FlaxEngine return _rand.Next(min, max); } - // Float - + /// + /// Generates a random value between min and max. + /// + /// The lower boundary. + /// The upper boundary. + /// A random between min and max. public static float RandomFloat(float min = 0.0f, float max = 1.0f) { return (float)_rand.NextDouble() * (max - min) + min; } + /// + /// Generates a random by using a single value as both upper and lower boundary. + /// + /// Defines both upper and lower boundary. + /// A random between +value and -value. public static float RandomUniformFloat(float value = 1.0f) { // Ensure that in case of negative values we still return a value between + value and - value. @@ -77,19 +107,22 @@ namespace FlaxEngine return (float)_rand.NextDouble() * (max - min) + min; } - // Quaternion - + /// + /// Generates a random . + /// + /// A random . public static Quaternion RandomQuaternion() { return Quaternion.Euler( RandomUniformFloat(180), RandomUniformFloat(180), - RandomUniformFloat(180) - ); + RandomUniformFloat(180)); } - // Vector - + /// + /// Generates a uniformly distributed random unit length vector point on a unit sphere. + /// + /// A random . public static Vector3 RandomVector3() { Vector3 output; @@ -108,13 +141,16 @@ namespace FlaxEngine return output; } + /// + /// Generates a uniformly distributed random unit length vector point on a unit sphere in 2D. + /// + /// A random public static Vector2 RandomVector2() { Vector2 output; do { - // Create random float with a mean of 0 and deviation of +-1; output.X = RandomFloat() * 2.0f - 1.0f; output.Y = RandomFloat() * 2.0f - 1.0f; @@ -125,8 +161,12 @@ namespace FlaxEngine return output; } - // Color - + /// + /// Generates a random color. + /// + /// Should the color be generated from a single random Hue value or separate values for each channel. + /// Randomize the alpha value. + /// A nice random color. public static Color RandomColor(bool trueRandom, bool randomAlpha) { float alpha = randomAlpha ? RandomFloat() : 1f;