add an extension to Random to generate a random Int64 value

This commit is contained in:
Michael Becker 2021-08-11 12:17:26 -04:00
parent 035c6cdd58
commit 05915bf21c

View File

@ -23,5 +23,18 @@ namespace MBS.Framework
{ {
return (x * Math.Pow(2, exp)); return (x * Math.Pow(2, exp));
} }
/// <summary>
/// Returns a random <see cref="long" /> between
/// <paramref name="minValue"/> and <paramref name="maxValue" />.
/// </summary>
/// <returns>The random number.</returns>
/// <param name="random">The instance of <see cref="Random" /> being extended.</param>
/// <param name="minValue">The inclusive minimum bound of the resulting random value.</param>
/// <param name="maxValue">The exclusive maximum bound of the resulting random value.</param>
public static long NextLong (this Random random, long minValue = 0, long maxValue = long.MaxValue)
{
return (long)((random.NextDouble() * (maxValue - minValue)) + minValue);
}
} }
} }