1
0
mirror of https://github.com/oliverbooth/X10D synced 2024-11-23 00:38:47 +00:00

(#35) Add Random.NextColor

This commit is contained in:
Oliver Booth 2021-03-09 16:56:42 +00:00
parent 89ce281656
commit 95fda962ed

View File

@ -56,6 +56,29 @@ namespace X10D.RandomExtensions
return random.NextDouble() >= 0.5;
}
/// <summary>
/// Returns a random color
/// </summary>
/// <param name="random"></param>
/// <returns></returns>
/// <exception cref="ArgumentNullException"></exception>
public static Color NextColor(this Random random)
{
if (random is null)
{
throw new ArgumentNullException(nameof(random));
}
var seed = random.Next();
var seededRandom = new Random(seed);
var r = (byte)(seededRandom.Next() % (byte.MaxValue + 1));
var g = (byte)(seededRandom.Next() % (byte.MaxValue + 1));
var b = (byte)(seededRandom.Next() % (byte.MaxValue + 1));
return System.Drawing.Color.FromArgb(r, g, b);
}
/// <summary>
/// Returns a non-negative random double-precision floating point number that is less than the specified maximum.
/// </summary>