Uuid constructor

Uuid()

Implementation

Uuid() {
  _byteToHex = new List<String>(256);
  _hexToByte = new Map<String, int>();

  // Easy number <-> hex conversion
  for (var i = 0; i < 256; i++) {
    var hex = new List<int>();
    hex.add(i);
    _byteToHex[i] = convert.hex.encode(hex);
    _hexToByte[_byteToHex[i]] = i;
  }

  // Sets initial seedBytes, node, and clock seq based on cryptoRNG.
  _seedBytes = UuidUtil.cryptoRNG();

  // Per 4.5, create a 48-bit node id (47 random bits + multicast bit = 1)
  _nodeId = [
    _seedBytes[0] | 0x01,
    _seedBytes[1],
    _seedBytes[2],
    _seedBytes[3],
    _seedBytes[4],
    _seedBytes[5]
  ];

  // Per 4.2.2, randomize (14 bit) clockseq
  _clockSeq = (_seedBytes[6] << 8 | _seedBytes[7]) & 0x3ffff;
}