Open RNG for plugins

This commit is contained in:
JustArchi
2020-06-12 13:00:32 +02:00
parent d40dbb2676
commit 32b376d85a

View File

@@ -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));