randombytes_array_len static method

Uint8List randombytes_array_len(
  1. Uint8List x,
  2. int len
)

Implementation

static Uint8List randombytes_array_len(Uint8List x, int len) {
  int ret = len % 4;
  Int64 rnd;
  for (int i = 0; i < len - ret; i += 4) {
    rnd = Int64(jrandom.nextInt(1 << 32));
    x[i + 0] = (rnd.shiftRightUnsigned(0).toInt());
    x[i + 1] = (rnd.shiftRightUnsigned(8).toInt());
    x[i + 2] = (rnd.shiftRightUnsigned(16).toInt());
    x[i + 3] = (rnd.shiftRightUnsigned(24).toInt());
  }
  if (ret > 0) {
    rnd = Int64(jrandom.nextInt(1 << 32));
    for (int i = len - ret; i < len; i++)
      x[i] = (rnd.shiftRightUnsigned(8 * i).toInt());
  }
  return x;
}