diff --git a/Directory.Packages.props b/Directory.Packages.props
index 6991b372b70..08de6f4e630 100644
--- a/Directory.Packages.props
+++ b/Directory.Packages.props
@@ -48,6 +48,7 @@
+
@@ -168,6 +169,7 @@
+
diff --git a/framework/src/Volo.Abp.Core/Volo.Abp.Core.csproj b/framework/src/Volo.Abp.Core/Volo.Abp.Core.csproj
index b1605bddd29..b0ac8741c32 100644
--- a/framework/src/Volo.Abp.Core/Volo.Abp.Core.csproj
+++ b/framework/src/Volo.Abp.Core/Volo.Abp.Core.csproj
@@ -1,4 +1,4 @@
-
+
@@ -16,6 +16,7 @@
+
@@ -32,6 +33,7 @@
+
diff --git a/framework/src/Volo.Abp.Core/Volo/Abp/RandomHelper.cs b/framework/src/Volo.Abp.Core/Volo/Abp/RandomHelper.cs
index 0a5b3ffd05b..f45b1491c78 100644
--- a/framework/src/Volo.Abp.Core/Volo/Abp/RandomHelper.cs
+++ b/framework/src/Volo.Abp.Core/Volo/Abp/RandomHelper.cs
@@ -1,7 +1,8 @@
using System;
using System.Collections.Generic;
-using System.Linq;
using JetBrains.Annotations;
+using ListShuffle;
+using ThreadSafeRandomizer;
namespace Volo.Abp;
@@ -11,8 +12,6 @@ namespace Volo.Abp;
///
public static class RandomHelper
{
- private static readonly Random Rnd = new Random();
-
///
/// Returns a random number within a specified range.
///
@@ -25,10 +24,7 @@ public static class RandomHelper
///
public static int GetRandom(int minValue, int maxValue)
{
- lock (Rnd)
- {
- return Rnd.Next(minValue, maxValue);
- }
+ return ThreadSafeRandom.Instance.Next(minValue, maxValue);
}
///
@@ -42,10 +38,7 @@ public static int GetRandom(int minValue, int maxValue)
///
public static int GetRandom(int maxValue)
{
- lock (Rnd)
- {
- return Rnd.Next(maxValue);
- }
+ return ThreadSafeRandom.Instance.Next(maxValue);
}
///
@@ -54,10 +47,7 @@ public static int GetRandom(int maxValue)
/// A 32-bit signed integer greater than or equal to zero and less than .
public static int GetRandom()
{
- lock (Rnd)
- {
- return Rnd.Next();
- }
+ return ThreadSafeRandom.Instance.Next();
}
///
@@ -91,18 +81,9 @@ public static T GetRandomOfList([NotNull] IList list)
/// items
public static List GenerateRandomizedList([NotNull] IEnumerable items)
{
- Check.NotNull(items, nameof(items));
-
- var currentList = new List(items);
- var randomList = new List();
-
- while (currentList.Any())
- {
- var randomIndex = RandomHelper.GetRandom(0, currentList.Count);
- randomList.Add(currentList[randomIndex]);
- currentList.RemoveAt(randomIndex);
- }
+ var list = new List(items);
+ list.Shuffle();
- return randomList;
+ return list;
}
}