From 95d61eff2c5d5425f8d11519c80b68e0b210ca55 Mon Sep 17 00:00:00 2001 From: Oliver Booth Date: Thu, 21 Apr 2022 17:40:50 +0100 Subject: [PATCH] Move RandomExtensions to child namespaces (#7) --- X10D/src/Drawing/RandomExtensions.cs | 32 +++++++++++++++++++ .../RandomExtensions.cs} | 2 +- X10D/src/RandomExtensions/RandomExtensions.cs | 26 +-------------- 3 files changed, 34 insertions(+), 26 deletions(-) create mode 100644 X10D/src/Drawing/RandomExtensions.cs rename X10D/src/{RandomExtensions/SystemNumerics/RandomExtensions.Numerics.cs => Numerics/RandomExtensions.cs} (99%) diff --git a/X10D/src/Drawing/RandomExtensions.cs b/X10D/src/Drawing/RandomExtensions.cs new file mode 100644 index 0000000..8f07e41 --- /dev/null +++ b/X10D/src/Drawing/RandomExtensions.cs @@ -0,0 +1,32 @@ +using System.Drawing; + +namespace X10D.Drawing; + +/// +/// Extension methods for . +/// +public static class RandomExtensions +{ + /// + /// Returns a random color. + /// + /// The instance. + /// A whose red, green, and blue components are all random, and whose alpha is 255 + /// is . + 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); + } +} diff --git a/X10D/src/RandomExtensions/SystemNumerics/RandomExtensions.Numerics.cs b/X10D/src/Numerics/RandomExtensions.cs similarity index 99% rename from X10D/src/RandomExtensions/SystemNumerics/RandomExtensions.Numerics.cs rename to X10D/src/Numerics/RandomExtensions.cs index 810523c..ddc46a2 100644 --- a/X10D/src/RandomExtensions/SystemNumerics/RandomExtensions.Numerics.cs +++ b/X10D/src/Numerics/RandomExtensions.cs @@ -1,6 +1,6 @@ using System.Numerics; -namespace X10D.SystemNumerics; +namespace X10D.Numerics; /// /// Extension methods for . diff --git a/X10D/src/RandomExtensions/RandomExtensions.cs b/X10D/src/RandomExtensions/RandomExtensions.cs index 1b7d357..447cf99 100644 --- a/X10D/src/RandomExtensions/RandomExtensions.cs +++ b/X10D/src/RandomExtensions/RandomExtensions.cs @@ -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; } - /// - /// Returns a random color. - /// - /// The instance. - /// A whose red, green, and blue components are all random, and whose alpha is 255 - /// is . - 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); - } - /// /// Returns a non-negative random double-precision floating point number that is less than the specified maximum. ///