Closed davalapar closed 5 years ago
async
const filehandle = fsPromises.open('/dev/urandom');
const urandom = async (length) => {
const buffer = Buffer.alloc(length);
await filehandle.read(buffer, 0, length, 0);
return buffer;
};
const close = () => filehandle.close();
sync
const fd = fs.openSync('/dev/urandom');
const urandom = (length) => {
const buffer = Buffer.alloc(length);
fs.readSync(fd, buffer, 0, 32, 0);
return buffer;
};
const close = () => fs.closeSync(fd);
urandom(32);