2024-08-17 14:27:18 +08:00
|
|
|
|
using System;
|
|
|
|
|
using JNGame.Math;
|
|
|
|
|
using JNGame.Sync.System;
|
|
|
|
|
using Plugins.JNGame.Util;
|
|
|
|
|
|
|
|
|
|
namespace JNGame.Sync.Frame.Service
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 随机数
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class JNRandomSystem : SLogicSystem
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
//随机数
|
|
|
|
|
private Func<LFloat,LFloat,LFloat> nRandomFloat;
|
|
|
|
|
private Func<int,int,int> nRandomInt;
|
|
|
|
|
|
|
|
|
|
//Id
|
2024-08-23 10:48:19 +08:00
|
|
|
|
private ulong _id = 0;
|
|
|
|
|
private ulong _idMin = ulong.MinValue;
|
|
|
|
|
private ulong _idMax = ulong.MaxValue;
|
2024-08-17 14:27:18 +08:00
|
|
|
|
|
|
|
|
|
public JNRandomSystem(int seed)
|
|
|
|
|
{
|
|
|
|
|
nRandomFloat = RandomUtil.SyncRandomFloat(seed);
|
|
|
|
|
nRandomInt = RandomUtil.SyncRandomInt(seed);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public LFloat Float()
|
|
|
|
|
{
|
|
|
|
|
return Float(0,1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public LFloat Float(LFloat min,LFloat max)
|
|
|
|
|
{
|
|
|
|
|
return nRandomFloat(min,max);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int Int(int max,int min)
|
|
|
|
|
{
|
|
|
|
|
return nRandomInt(max,min);
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-23 10:48:19 +08:00
|
|
|
|
public ulong NextId()
|
2024-08-17 14:27:18 +08:00
|
|
|
|
{
|
|
|
|
|
return ++_id;
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-23 10:48:19 +08:00
|
|
|
|
public void SetIdValue(ulong min,ulong max)
|
2024-08-17 14:27:18 +08:00
|
|
|
|
{
|
2024-08-22 20:37:39 +08:00
|
|
|
|
if (_id < min)
|
2024-08-17 14:27:18 +08:00
|
|
|
|
{
|
2024-08-22 20:37:39 +08:00
|
|
|
|
_id = min;
|
|
|
|
|
}
|
|
|
|
|
_idMin = min;
|
|
|
|
|
_idMax = max;
|
|
|
|
|
}
|
2024-08-17 14:27:18 +08:00
|
|
|
|
}
|
|
|
|
|
}
|