mirror of
https://github.com/oliverbooth/X10D
synced 2024-11-23 00:18:47 +00:00
(#35) Add Random.NextColor
This commit is contained in:
parent
89ce281656
commit
95fda962ed
@ -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>
|
||||
|
Loading…
Reference in New Issue
Block a user