diff --git a/X10D/src/CharExtensions.cs b/X10D/src/CharExtensions.cs
index 0f794de..9bfca63 100644
--- a/X10D/src/CharExtensions.cs
+++ b/X10D/src/CharExtensions.cs
@@ -18,7 +18,7 @@
/// Returns a containing characters.
public static string Random(this char[] chars, int length)
{
- return chars.Random(length, new Random());
+ return chars.Random(length, RandomExtensions.Random);
}
///
@@ -47,7 +47,7 @@
/// Returns a containing characters.
public static string Random(this IEnumerable chars, int length)
{
- return chars.Random(length, new Random());
+ return chars.Random(length, RandomExtensions.Random);
}
///
diff --git a/X10D/src/RandomExtensions.cs b/X10D/src/RandomExtensions.cs
index 70c4657..2ae2147 100644
--- a/X10D/src/RandomExtensions.cs
+++ b/X10D/src/RandomExtensions.cs
@@ -9,22 +9,36 @@
///
public static class RandomExtensions
{
+ ///
+ /// Gets the instance to which other extension methods may refer, when one is
+ /// needed but not provided.
+ ///
+ internal static Random Random { get; } = new Random();
+
///
/// Returns either or based on 's next
/// generation.
///
- /// The instance.
+ /// The instance.
+ /// Returns or depending on the return value
+ /// from .
+ /// is .
public static bool CoinToss(this Random random)
{
+ if (random is null)
+ {
+ throw new ArgumentNullException(nameof(random));
+ }
+
return random.Next(2) == 0;
}
///
- /// Returns a random element from using the instance.
+ /// Returns a random element from using the instance.
///
/// The collection type.
- /// The instance.
- /// The collection to draw from.
+ /// The instance.
+ /// The collection from which to draw.
/// Returns a random element of type from .
public static T OneOf(this Random random, params T[] source)
{
@@ -32,11 +46,11 @@
}
///
- /// Returns a random element from using the instance.
+ /// Returns a random element from using the instance.
///
/// The collection type.
- /// The instance.
- /// The collection to draw from.
+ /// The instance.
+ /// The collection from which to draw.
/// Returns a random element of type from .
public static T OneOf(this Random random, IList source)
{
diff --git a/X10D/src/StringExtensions.cs b/X10D/src/StringExtensions.cs
index 87a1edc..c329e3c 100644
--- a/X10D/src/StringExtensions.cs
+++ b/X10D/src/StringExtensions.cs
@@ -105,7 +105,7 @@
/// Returns a containing characters.
public static string Random(this string str, int length)
{
- return str.Random(length, new Random());
+ return str.Random(length, RandomExtensions.Random);
}
///
@@ -146,7 +146,7 @@
/// Returns a containing the characters in , rearranged.
public static string Shuffle(this string str)
{
- return str.Shuffle(new Random());
+ return str.Shuffle(RandomExtensions.Random);
}
///