mirror of
https://github.com/ShareX/ShareX.git
synced 2024-09-30 01:07:21 +13:00
Added Run method to RandomCrypto and RandomFast
This commit is contained in:
parent
6346472eab
commit
8d008fe2f7
5 changed files with 60 additions and 10 deletions
|
@ -46,7 +46,7 @@ public int Minimum
|
||||||
{
|
{
|
||||||
if (value < 0)
|
if (value < 0)
|
||||||
{
|
{
|
||||||
throw new ArgumentOutOfRangeException("Minimum");
|
throw new ArgumentOutOfRangeException(nameof(Minimum));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (maximum < value)
|
if (maximum < value)
|
||||||
|
@ -81,7 +81,7 @@ public int Maximum
|
||||||
{
|
{
|
||||||
if (value < 0)
|
if (value < 0)
|
||||||
{
|
{
|
||||||
throw new ArgumentOutOfRangeException("Maximum");
|
throw new ArgumentOutOfRangeException(nameof(Maximum));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (minimum > value)
|
if (minimum > value)
|
||||||
|
@ -114,9 +114,9 @@ public int Value
|
||||||
{
|
{
|
||||||
if (this.value != value)
|
if (this.value != value)
|
||||||
{
|
{
|
||||||
if ((value < minimum) || (value > maximum))
|
if (value < minimum || value > maximum)
|
||||||
{
|
{
|
||||||
throw new ArgumentOutOfRangeException("Value");
|
throw new ArgumentOutOfRangeException(nameof(Value));
|
||||||
}
|
}
|
||||||
|
|
||||||
this.value = value;
|
this.value = value;
|
||||||
|
|
|
@ -44,8 +44,8 @@ public static class Extensions
|
||||||
{
|
{
|
||||||
public static void ForEach<T>(this IEnumerable<T> source, Action<T> action)
|
public static void ForEach<T>(this IEnumerable<T> source, Action<T> action)
|
||||||
{
|
{
|
||||||
if (source == null) throw new ArgumentNullException("source");
|
if (source == null) throw new ArgumentNullException(nameof(source));
|
||||||
if (action == null) throw new ArgumentNullException("action");
|
if (action == null) throw new ArgumentNullException(nameof(action));
|
||||||
|
|
||||||
foreach (T item in source)
|
foreach (T item in source)
|
||||||
{
|
{
|
||||||
|
|
|
@ -53,7 +53,7 @@ public static int Next(int maxValue)
|
||||||
{
|
{
|
||||||
if (maxValue < 0)
|
if (maxValue < 0)
|
||||||
{
|
{
|
||||||
throw new ArgumentOutOfRangeException("maxValue");
|
throw new ArgumentOutOfRangeException(nameof(maxValue));
|
||||||
}
|
}
|
||||||
|
|
||||||
return Next(0, maxValue);
|
return Next(0, maxValue);
|
||||||
|
@ -69,7 +69,7 @@ public static int Next(int minValue, int maxValue)
|
||||||
|
|
||||||
if (minValue > maxValue)
|
if (minValue > maxValue)
|
||||||
{
|
{
|
||||||
throw new ArgumentOutOfRangeException("minValue");
|
throw new ArgumentOutOfRangeException(nameof(minValue));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (minValue == maxValue)
|
if (minValue == maxValue)
|
||||||
|
@ -115,7 +115,7 @@ public static void NextBytes(byte[] buffer)
|
||||||
{
|
{
|
||||||
if (buffer == null)
|
if (buffer == null)
|
||||||
{
|
{
|
||||||
throw new ArgumentNullException("buffer");
|
throw new ArgumentNullException(nameof(buffer));
|
||||||
}
|
}
|
||||||
|
|
||||||
lock (randomLock)
|
lock (randomLock)
|
||||||
|
@ -126,7 +126,22 @@ public static void NextBytes(byte[] buffer)
|
||||||
|
|
||||||
public static T Pick<T>(params T[] array)
|
public static T Pick<T>(params T[] array)
|
||||||
{
|
{
|
||||||
|
if (array == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(array));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (array.Length == 0)
|
||||||
|
{
|
||||||
|
throw new ArgumentException(nameof(array));
|
||||||
|
}
|
||||||
|
|
||||||
return array[Next(array.Length - 1)];
|
return array[Next(array.Length - 1)];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void Run(params Action[] actions)
|
||||||
|
{
|
||||||
|
Pick(actions)();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -47,6 +47,11 @@ public static int Next()
|
||||||
/// <returns>A 32-bit signed integer that is greater than or equal to 0 and less than or equal to <paramref name="maxValue"/>.</returns>
|
/// <returns>A 32-bit signed integer that is greater than or equal to 0 and less than or equal to <paramref name="maxValue"/>.</returns>
|
||||||
public static int Next(int maxValue)
|
public static int Next(int maxValue)
|
||||||
{
|
{
|
||||||
|
if (maxValue < 0)
|
||||||
|
{
|
||||||
|
throw new ArgumentOutOfRangeException(nameof(maxValue));
|
||||||
|
}
|
||||||
|
|
||||||
lock (randomLock)
|
lock (randomLock)
|
||||||
{
|
{
|
||||||
return random.Next(maxValue + 1);
|
return random.Next(maxValue + 1);
|
||||||
|
@ -59,6 +64,16 @@ public static int Next(int maxValue)
|
||||||
/// <returns>A 32-bit signed integer that is greater than or equal to <paramref name="minValue"/> and less than or equal to <paramref name="maxValue"/>.</returns>
|
/// <returns>A 32-bit signed integer that is greater than or equal to <paramref name="minValue"/> and less than or equal to <paramref name="maxValue"/>.</returns>
|
||||||
public static int Next(int minValue, int maxValue)
|
public static int Next(int minValue, int maxValue)
|
||||||
{
|
{
|
||||||
|
if (minValue > maxValue)
|
||||||
|
{
|
||||||
|
throw new ArgumentOutOfRangeException(nameof(minValue));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (minValue == maxValue)
|
||||||
|
{
|
||||||
|
return minValue;
|
||||||
|
}
|
||||||
|
|
||||||
lock (randomLock)
|
lock (randomLock)
|
||||||
{
|
{
|
||||||
return random.Next(minValue, maxValue + 1);
|
return random.Next(minValue, maxValue + 1);
|
||||||
|
@ -79,6 +94,11 @@ public static double NextDouble()
|
||||||
/// <param name="buffer">An array of bytes to contain random numbers.</param>
|
/// <param name="buffer">An array of bytes to contain random numbers.</param>
|
||||||
public static void NextBytes(byte[] buffer)
|
public static void NextBytes(byte[] buffer)
|
||||||
{
|
{
|
||||||
|
if (buffer == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(buffer));
|
||||||
|
}
|
||||||
|
|
||||||
lock (randomLock)
|
lock (randomLock)
|
||||||
{
|
{
|
||||||
random.NextBytes(buffer);
|
random.NextBytes(buffer);
|
||||||
|
@ -87,7 +107,22 @@ public static void NextBytes(byte[] buffer)
|
||||||
|
|
||||||
public static T Pick<T>(params T[] array)
|
public static T Pick<T>(params T[] array)
|
||||||
{
|
{
|
||||||
|
if (array == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(array));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (array.Length == 0)
|
||||||
|
{
|
||||||
|
throw new ArgumentException(nameof(array));
|
||||||
|
}
|
||||||
|
|
||||||
return array[Next(array.Length - 1)];
|
return array[Next(array.Length - 1)];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void Run(params Action[] actions)
|
||||||
|
{
|
||||||
|
Pick(actions)();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -56,7 +56,7 @@ public JiraUpload(string issuePrefix, GetSummaryHandler getSummary) : this()
|
||||||
{
|
{
|
||||||
if (getSummary == null)
|
if (getSummary == null)
|
||||||
{
|
{
|
||||||
throw new ArgumentNullException("getSummary");
|
throw new ArgumentNullException(nameof(getSummary));
|
||||||
}
|
}
|
||||||
this.issuePrefix = issuePrefix;
|
this.issuePrefix = issuePrefix;
|
||||||
this.getSummary = getSummary;
|
this.getSummary = getSummary;
|
||||||
|
|
Loading…
Reference in a new issue