randomBytes function

List<int> randomBytes(
  1. dynamic count,
  2. [bool typedList = false]
)

Random bytes array.

count is bytes length, if typedList is false , will return a fixed-length array (Uint8List).

typedList default value is false

Implementation

List<int> randomBytes(count, [bool typedList = false]) {
  var random = math.Random();
  var bytes;
  if (typedList) {
    bytes = Uint8List(count);
    for (var i = 0; i < count; i++) {
      bytes[i] = random.nextInt(256);
    }
  } else {
    bytes = <int>[];
    for (var i = 0; i < count; i++) {
      bytes.add(random.nextInt(256));
    }
  }
  return bytes;
}