generate function Null safety

List<int> generate(
  1. int length
)

Generates a random salt of length bytes from a cryptographically secure random number generator.

Each element of this list is a byte.

Implementation

List<int> generate(int length) {
  final buffer = Uint8List(length);
  final rng = Random.secure();
  for (var i = 0; i < length; i++) {
    buffer[i] = rng.nextInt(256);
  }

  return buffer;
}