byteList method

List<int> byteList(
  1. int length
)

Returns a list of random bytes with a given length.

Implementation

List<int> byteList(int length) {
  final rc = List.filled(length, 0);
  int value;
  for (var ix = length - 1; ix >= 4; ix -= 4) {
    value = next();
    rc[ix] = value & 0xff;
    value >>= 8;
    rc[ix - 1] = value & 0xff;
    value >>= 8;
    rc[ix - 2] = value & 0xff;
    value >>= 8;
    rc[ix - 3] = value & 0xff;
  }
  value = next();
  for (var ix = length >= 4 ? 3 : length - 1; ix >= 0; ix--) {
    rc[ix] = value & 0xff;
    value >>= 8;
  }
  return rc;
}