38 lines
858 B
C#
Raw Normal View History

2024-01-26 19:15:07 +08:00
using System;
namespace Plugins.JNGame.Util
{
public static class RandomUtil
{
public static Func<double> SyncRandom(int seed,int start = 1)
{
for(var i = 0; i < start; i++){
seed = (seed * 9301 + 49297) % 233280;
}
return () =>
{
seed = (seed * 9301 + 49297) % 233280;
var rnd = seed / 233280.0;
return 0 + rnd * (1 - 0);
};
}
public static Func<int,int,int> SyncRandomInt(int seed,int start = 1)
{
var nRandom = SyncRandom(seed, start);
return (min, max) => (int)(Math.Round(nRandom() * (max - min)) + min);
}
public static Func<int> Next(int start)
{
return () => start++;
}
}
}