I would like to set the first 29 bits of a 16-byte ArrayBuffer
to a random value in the range [0, 2^28 - 1]
, independently of the system endianness.
Following is my attempt, but this (potentially) sets all 32 bits. What can I do? Is there a way to do something like randomNumberHere | 0x1FFFFFFF
?
let buffer = new ArrayBuffer(16);
let view = new Uint32Array(buffer.slice(0, 4));
window.crypto.getRandomValues(view);
Aucun commentaire:
Enregistrer un commentaire