Test/Program.cs
(开头部分) 3KB这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。
using Nova.IdGenerator;
using Nova.IdGenerator.Interface;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection.Emit;
using System.Text;
using System.Threading.Tasks;
namespace Test
{
internal class Program
{
static void Main(string[] args)
{
M2();
}
static void M1()
{
int times = 100;
//机器ID
ushort workerID = 1;
//1:飘移算法,2:经典算法
short method = 2;
//数据中心ID
uint dataCenterID = 0;
IdGeneratorOptions options = new IdGeneratorOptions(workerID)
{
DataCenterId = dataCenterID,
Method = method
};
Generator.SetIdGenerator(options);
List<long> IdList = new List<long>();
for (int i = 0; i < times; i++)
{
var currentID = Generator.NextId();
IdList.Add(currentID);
Console.WriteLine(currentID);
}
int IdCount = IdList.Count;
int DistinctIDCount = IdList.Distinct().ToList().Count;
Console.WriteLine($"{IdCount}, {DistinctIDCount}");
}
// 更多设置
static void M2()
{
//机器ID(必填)
ushort workerID = 1;
//数据中心ID
uint dataCenterId = 0;
// 1:飘移算法,2:经典雪花算法
short method = 1;
//基础时间,设定在2020年2月2日,可以设置为之前的时间,如果不理解这个字段的意义,切记随意修改
DateTime baseTime = new DateTime(2020, 2, 2, 2, 2, 2);
//机器码位长(最大15)
byte workerIdBitLength = 4;
//序列数位长(可选值:3-21)
后面还有 33 行代码,解锁后查看完整代码
24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明
AI 解读
登录后可用,每次 10 积分,解读结果公开显示在下面。
还没有人解读过这个文件。
