From 32b376d85a5f975a967832350fc364a9192b64ef Mon Sep 17 00:00:00 2001 From: JustArchi Date: Fri, 12 Jun 2020 13:00:32 +0200 Subject: [PATCH] Open RNG for plugins --- ArchiSteamFarm/Utilities.cs | 43 +++++++++++++++++++++++++++++++------ 1 file changed, 37 insertions(+), 6 deletions(-) diff --git a/ArchiSteamFarm/Utilities.cs b/ArchiSteamFarm/Utilities.cs index c33a285cf..46b54dde0 100644 --- a/ArchiSteamFarm/Utilities.cs +++ b/ArchiSteamFarm/Utilities.cs @@ -196,6 +196,43 @@ namespace ArchiSteamFarm { return (text.Length % 2 == 0) && text.All(Uri.IsHexDigit); } + [PublicAPI] + public static int RandomNext() { + lock (Random) { + return Random.Next(); + } + } + + [PublicAPI] + public static int RandomNext(int maxValue) { + if (maxValue < 0) { + throw new ArgumentOutOfRangeException(nameof(maxValue)); + } + + if (maxValue <= 1) { + return maxValue; + } + + lock (Random) { + return Random.Next(maxValue); + } + } + + [PublicAPI] + public static int RandomNext(int minValue, int maxValue) { + if (minValue > maxValue) { + throw new ArgumentOutOfRangeException(nameof(minValue) + " && " + nameof(maxValue)); + } + + if (minValue >= maxValue - 1) { + return minValue; + } + + lock (Random) { + return Random.Next(minValue, maxValue); + } + } + [ItemNotNull] [NotNull] [PublicAPI] @@ -268,12 +305,6 @@ namespace ArchiSteamFarm { return cookies.Count > 0 ? (from Cookie cookie in cookies where cookie.Name.Equals(name) select cookie.Value).FirstOrDefault() : null; } - internal static int RandomNext() { - lock (Random) { - return Random.Next(); - } - } - internal static bool RelativeDirectoryStartsWith(string directory, params string[] prefixes) { if (string.IsNullOrEmpty(directory) || (prefixes == null) || (prefixes.Length == 0)) { ASF.ArchiLogger.LogNullError(nameof(directory) + " || " + nameof(prefixes));