mirror of
https://github.com/ShareX/ShareX.git
synced 2024-09-30 01:07:21 +13:00
Using lock for random
This commit is contained in:
parent
41777a7a41
commit
79f0c09546
2 changed files with 18 additions and 4 deletions
|
@ -295,8 +295,7 @@ public static Color CMYKToColor(CMYK cmyk)
|
|||
|
||||
public static Color RandomColor()
|
||||
{
|
||||
Random rand = Helpers.Random;
|
||||
return Color.FromArgb(rand.Next(256), rand.Next(256), rand.Next(256));
|
||||
return Color.FromArgb(Helpers.Random(255), Helpers.Random(255), Helpers.Random(255));
|
||||
}
|
||||
|
||||
public static Color ParseColor(string color)
|
||||
|
|
|
@ -54,9 +54,24 @@ public static class Helpers
|
|||
public const string URLPathCharacters = URLCharacters + "/"; // 47
|
||||
public const string ValidURLCharacters = URLPathCharacters + ":?#[]@!$&'()*+,;=";
|
||||
|
||||
public static readonly Random Random = new Random();
|
||||
private static readonly object randomLock = new object();
|
||||
private static readonly Random random = new Random();
|
||||
|
||||
public static readonly Version OSVersion = Environment.OSVersion.Version;
|
||||
|
||||
public static int Random(int max)
|
||||
{
|
||||
return Random(0, max);
|
||||
}
|
||||
|
||||
public static int Random(int min, int max)
|
||||
{
|
||||
lock (randomLock)
|
||||
{
|
||||
return random.Next(min, max + 1);
|
||||
}
|
||||
}
|
||||
|
||||
public static string GetFilenameExtension(string filePath)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(filePath) && filePath.Contains('.'))
|
||||
|
@ -131,7 +146,7 @@ public static string HourTo12(int hour)
|
|||
|
||||
public static char GetRandomChar(string chars)
|
||||
{
|
||||
return chars[Random.Next(chars.Length)];
|
||||
return chars[Random(chars.Length - 1)];
|
||||
}
|
||||
|
||||
public static string GetRandomString(string chars, int length)
|
||||
|
|
Loading…
Reference in a new issue