2023-02-08 03:32:12 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Threading;
|
|
|
|
|
|
|
|
|
|
namespace SharpChat {
|
|
|
|
|
public static class SharpId {
|
|
|
|
|
private const long EPOCH = 1588377600000;
|
|
|
|
|
private static int Counter = 0;
|
|
|
|
|
|
2024-05-13 20:55:54 +00:00
|
|
|
|
public static long Next() {
|
|
|
|
|
long num = DateTimeOffset.Now.ToUnixTimeMilliseconds() - EPOCH;
|
|
|
|
|
num <<= 8;
|
|
|
|
|
num |= (ushort)(Interlocked.Increment(ref Counter) & 0xFFFF);
|
|
|
|
|
return num;
|
|
|
|
|
}
|
2023-02-08 03:32:12 +00:00
|
|
|
|
}
|
|
|
|
|
}
|