const len = 16;
// Generate random hex string:
const bytes = crypto.getRandomValues(new Uint8Array(Math.ceil(len / 2)));
Array.from(bytes, (b) => b.toString(16).padStart(2, "0"))
.join("")
.slice(0, len); // for odd len values, need to trim the last char
// Generate random hex string:
Array.from({ length: len }, () =>
Math.floor(Math.random() * 16).toString(16)
).join("");