generateRandomBytes function

Uint8List generateRandomBytes(
  1. int bytesCount
)

Generates random bytes using a cryptographically secure PRNG.

Uses Dart's Random.secure() which provides a cryptographically secure pseudorandom number generator suitable for generating keys, salts, and other security-sensitive random data.

Parameters:

  • bytesCount: Number of random bytes to generate

Returns: Uint8List containing cryptographically secure random bytes

Example:

final salt = generateRandomBytes(32); // 256-bit random salt

Implementation

Uint8List generateRandomBytes(int bytesCount) {
  final random = Random.secure();
  final result = Uint8List(bytesCount);
  for (int i = 0; i < bytesCount; i++) {
    result[i] = random.nextInt(256);
  }
  return result;
}