genMsgId function

String genMsgId()

生成 32 位无横线 UUID,满足 go-chat msg_id 长度要求(≥30)

Implementation

String genMsgId() {
  final rnd = Random.secure();
  final bytes = List<int>.generate(16, (_) => rnd.nextInt(256));
  bytes[6] = (bytes[6] & 0x0f) | 0x40;
  bytes[8] = (bytes[8] & 0x3f) | 0x80;
  final hex = bytes.map((b) => b.toRadixString(16).padLeft(2, '0')).join();
  return hex;
}