uuidV7 static method
Millisecond time + random, sorts by creation; best for database keys (v7). UUUID.uuidV7()
Implementation
static String uuidV7() {
int ms = DateTime.now().millisecondsSinceEpoch;
if (ms <= _lastV7) {
ms = _lastV7;
_v7Counter++;
} else {
_v7Counter = UEncryption.randomBytes(2).buffer.asByteData().getUint16(0) & 0x7ff;
}
_lastV7 = ms;
final Uint8List b = UEncryption.randomBytes(16);
for (int i = 0; i < 6; i++) {
b[i] = (ms ~/ pow(2, 8 * (5 - i)).toInt()) & 0xff;
}
b[6] = (_v7Counter >> 8) & 0x0f;
b[7] = _v7Counter & 0xff;
return _format(_version(b, 7));
}