randomBytes static method

Uint8List randomBytes(
  1. int length
)

Generates a random byte sequence of given length

Implementation

static Uint8List randomBytes(int length) {
  final Uint8List buffer = Uint8List(length);
  final Random range = Random.secure();

  for (int i = 0; i < length; i++) {
    buffer[i] = range.nextInt(256);
  }

  return buffer;
}