generateUid method

int generateUid()

Implementation

int generateUid() {
  var rng = Random();
  for (var i = 0; i < 1000; ++i) {
    // Dart can only generate random numbers up to 1 << 32, so concat two of them and remove the upper bit to make the number non-negative
    var uid = rng.nextInt(1 << 32);
    uid |= rng.nextInt(1 << 32) << 32;
    uid &= ~(1 << 63);
    if (uid != 0 && !containsUid(uid)) return uid;
  }

  throw StateError('internal error: could not generate a unique UID');
}