Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
<PackageVersion Include="JetBrains.Annotations" Version="2024.2.0" />
<PackageVersion Include="LdapForNet" Version="2.7.15" />
<PackageVersion Include="LibGit2Sharp" Version="0.30.0" />
<PackageVersion Include="ListShuffle" Version="2.1.0" />
<PackageVersion Include="Magick.NET-Q16-AnyCPU" Version="13.4.0" />
<PackageVersion Include="MailKit" Version="4.8.0" />
<PackageVersion Include="Markdig.Signed" Version="0.37.0" />
Expand Down Expand Up @@ -168,6 +169,7 @@
<PackageVersion Include="System.Text.Json" Version="9.0.0-rc.2.24473.5" />
<PackageVersion Include="System.Threading.Tasks.Extensions" Version="4.5.4" />
<PackageVersion Include="System.IdentityModel.Tokens.Jwt" Version="8.1.0" />
<PackageVersion Include="ThreadSafeRandomizer" Version="1.2.0" />
<PackageVersion Include="TimeZoneConverter" Version="6.1.0" />
<PackageVersion Include="Unidecode.NET" Version="2.1.0" />
<PackageVersion Include="xunit" Version="2.9.2" />
Expand Down
4 changes: 3 additions & 1 deletion framework/src/Volo.Abp.Core/Volo.Abp.Core.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<Import Project="..\..\..\configureawait.props" />
<Import Project="..\..\..\common.props" />
Expand All @@ -16,6 +16,7 @@
<RootNamespace />
</PropertyGroup>
<ItemGroup>
<PackageReference Include="ListShuffle" />
<PackageReference Include="System.Collections.Immutable" />
<PackageReference Include="Microsoft.Extensions.Localization" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" />
Expand All @@ -32,6 +33,7 @@
<PackageReference Include="System.Linq.Queryable" />
<PackageReference Include="JetBrains.Annotations" />
<PackageReference Include="Nito.AsyncEx.Context" />
<PackageReference Include="ThreadSafeRandomizer" />
</ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' ">
<PackageReference Include="System.Threading.Tasks.Extensions" />
Expand Down
35 changes: 8 additions & 27 deletions framework/src/Volo.Abp.Core/Volo/Abp/RandomHelper.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
using System;
using System.Collections.Generic;
using System.Linq;
using JetBrains.Annotations;
using ListShuffle;
using ThreadSafeRandomizer;

namespace Volo.Abp;

Expand All @@ -11,8 +12,6 @@ namespace Volo.Abp;
/// </summary>
public static class RandomHelper
{
private static readonly Random Rnd = new Random();

/// <summary>
/// Returns a random number within a specified range.
/// </summary>
Expand All @@ -25,10 +24,7 @@ public static class RandomHelper
/// </returns>
public static int GetRandom(int minValue, int maxValue)
{
lock (Rnd)
{
return Rnd.Next(minValue, maxValue);
}
return ThreadSafeRandom.Instance.Next(minValue, maxValue);
}

/// <summary>
Expand All @@ -42,10 +38,7 @@ public static int GetRandom(int minValue, int maxValue)
/// </returns>
public static int GetRandom(int maxValue)
{
lock (Rnd)
{
return Rnd.Next(maxValue);
}
return ThreadSafeRandom.Instance.Next(maxValue);
}

/// <summary>
Expand All @@ -54,10 +47,7 @@ public static int GetRandom(int maxValue)
/// <returns>A 32-bit signed integer greater than or equal to zero and less than <see cref="int.MaxValue"/>.</returns>
public static int GetRandom()
{
lock (Rnd)
{
return Rnd.Next();
}
return ThreadSafeRandom.Instance.Next();
}

/// <summary>
Expand Down Expand Up @@ -91,18 +81,9 @@ public static T GetRandomOfList<T>([NotNull] IList<T> list)
/// <param name="items">items</param>
public static List<T> GenerateRandomizedList<T>([NotNull] IEnumerable<T> items)
{
Check.NotNull(items, nameof(items));

var currentList = new List<T>(items);
var randomList = new List<T>();

while (currentList.Any())
{
var randomIndex = RandomHelper.GetRandom(0, currentList.Count);
randomList.Add(currentList[randomIndex]);
currentList.RemoveAt(randomIndex);
}
var list = new List<T>(items);
list.Shuffle();

return randomList;
return list;
}
}