调整雪花算法

This commit is contained in:
yubaolee
2021-03-29 23:35:02 +08:00
parent 31811e9d9c
commit a333234f0c
15 changed files with 417 additions and 193 deletions

View File

@@ -11,14 +11,16 @@ namespace Infrastructure.Test
public void Generate()
{
// 全局初始化设置WorkerId默认最大2^16-1。初始化过程全局只需一次且必须最先设置
var options = new IdGeneratorOptions(){ WorkerId = 1};
IIdGenerator IdHelper = new YitIdGenerator(options);
var options = new IdGeneratorOptions()
{
Method = 1,
WorkerId = 1
};
// 初始化以后就可以在需要的地方调用方法生成ID。
long val =IdHelper.NewLong();
int val2 = (int)val;
Console.WriteLine($"val:{val}/int:{val2}");
YitIdHelper.SetIdGenerator(options);
long newId = YitIdHelper.NextId();
Console.WriteLine("=====================================");
Console.WriteLine("生成的 Id" + newId);
}
}