com.alicizax.unity.framework/Runtime/ABase/Extension/Extension/ThreadLocalRandom.cs
2025-10-11 15:18:09 +08:00

23 lines
614 B
C#

using System.Threading;
namespace System
{
/// <summary>
/// 线程私有random对象
/// </summary>
[UnityEngine.Scripting.Preserve]
public static class ThreadLocalRandom
{
private static int _seed = Environment.TickCount;
private static readonly ThreadLocal<Random> _rng = new ThreadLocal<Random>(() => new Random(Interlocked.Increment(ref _seed)));
/// <summary>
/// The current random number seed available to this thread
/// </summary>
public static Random Current
{
get { return _rng.Value; }
}
}
}