diff --git a/Source/Engine/Utilities/Extensions.cs b/Source/Engine/Utilities/Extensions.cs
index b3f6d2053..3eb31e1d2 100644
--- a/Source/Engine/Utilities/Extensions.cs
+++ b/Source/Engine/Utilities/Extensions.cs
@@ -211,6 +211,17 @@ namespace FlaxEngine.Utilities
/// A thats either true or false.
public static bool NextBool(this Random random, float weight = 0.5f) => random.NextDouble() < weight;
+ ///
+ /// Generates a random value up until an exclusive maximum.
+ ///
+ /// An instance of .
+ /// The maximum value. If it's zero, a maximum of 256 is used
+ /// A random between min and max.
+ public static byte NextByte(this Random random, byte max = 0)
+ {
+ return max == 0 ? (byte)(random.Next() % 256) : (byte)random.Next(max);
+ }
+
///
/// Generates a random value between min and max.
///
@@ -218,9 +229,9 @@ namespace FlaxEngine.Utilities
/// The minimum value.
/// The maximum value.
/// A random between min and max.
- public static byte NextByte(this Random random, byte min = 0, byte max = byte.MaxValue)
+ public static byte NextByte(this Random random, byte min, byte max)
{
- return (byte)random.Next(min, max == byte.MaxValue ? byte.MaxValue + 1 : max);
+ return (byte)random.Next(min, max);
}
///