ConnectionId.random constructor

ConnectionId.random({
  1. int length = defaultCidLength,
})

Generates a new random ConnectionId with the default length.

Implementation

factory ConnectionId.random({int length = defaultCidLength}) {
  if (length < minCidLength || length > maxCidLength) {
    throw ArgumentError(
      'ConnectionId length must be between $minCidLength and $maxCidLength, got $length');
  }
  final random = Random.secure();
  final bytes = Uint8List(length);
  for (int i = 0; i < length; i++) {
    bytes[i] = random.nextInt(256);
  }
  return ConnectionId.fromUint8List(bytes);
}