mirror of
https://gitee.com/jisol/jisol-game/
synced 2025-06-26 19:34:47 +00:00
38 lines
858 B
C#
38 lines
858 B
C#
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++;
|
|
}
|
|
|
|
}
|
|
} |