How to use the bindings/wasi.random_get function in bindings

To help you get started, we’ve selected a few bindings examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github jedisct1 / as-wasi / assembly / wasa.ts View on Github external
static randomFill(buffer: ArrayBuffer): void {
    let len = buffer.byteLength;
    let ptr = changetype(buffer);
    while (len > 0) {
      let chunk = min(len, 256);
      if (random_get(ptr, chunk) != errno.SUCCESS) {
        abort();
      }
      len -= chunk;
      ptr += chunk;
    }
  }