randomBytes static method

Uint8List randomBytes(
  1. int length
)

Generates cryptographically secure random bytes.

length - Number of random bytes to generate.

Implementation

static Uint8List randomBytes(int length) {
  if (length <= 0) {
    throw ArgumentError('Length must be positive');
  }
  final random = Random.secure();
  return Uint8List.fromList(
    List.generate(length, (_) => random.nextInt(256)),
  );
}