mirror of
https://github.com/oliverbooth/X10D
synced 2024-11-10 03:45:41 +00:00
Move RandomExtensions to child namespaces (#7)
This commit is contained in:
parent
44c8b87069
commit
95d61eff2c
32
X10D/src/Drawing/RandomExtensions.cs
Normal file
32
X10D/src/Drawing/RandomExtensions.cs
Normal file
@ -0,0 +1,32 @@
|
||||
using System.Drawing;
|
||||
|
||||
namespace X10D.Drawing;
|
||||
|
||||
/// <summary>
|
||||
/// Extension methods for <see cref="Random" />.
|
||||
/// </summary>
|
||||
public static class RandomExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Returns a random color.
|
||||
/// </summary>
|
||||
/// <param name="random">The <see cref="System.Random" /> instance.</param>
|
||||
/// <returns>A <see cref="Color" /> whose red, green, and blue components are all random, and whose alpha is 255</returns>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="random" /> is <see langword="null" />.</exception>
|
||||
public static Color NextColor(this Random random)
|
||||
{
|
||||
if (random is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(random));
|
||||
}
|
||||
|
||||
int 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 Color.FromArgb(r, g, b);
|
||||
}
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
using System.Numerics;
|
||||
|
||||
namespace X10D.SystemNumerics;
|
||||
namespace X10D.Numerics;
|
||||
|
||||
/// <summary>
|
||||
/// Extension methods for <see cref="System.Random" />.
|
@ -1,5 +1,4 @@
|
||||
using System.Drawing;
|
||||
using System.Globalization;
|
||||
using System.Globalization;
|
||||
using System.Text;
|
||||
|
||||
namespace X10D;
|
||||
@ -52,29 +51,6 @@ public static class RandomExtensions
|
||||
return random.NextDouble() >= 0.5;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a random color.
|
||||
/// </summary>
|
||||
/// <param name="random">The <see cref="System.Random" /> instance.</param>
|
||||
/// <returns>A <see cref="Color" /> whose red, green, and blue components are all random, and whose alpha is 255</returns>
|
||||
/// <exception cref="ArgumentNullException"><paramref name="random" /> is <see langword="null" />.</exception>
|
||||
public static Color NextColor(this Random random)
|
||||
{
|
||||
if (random is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(random));
|
||||
}
|
||||
|
||||
int 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 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