<p id="myRandText">The random numbers are:</p>
<button type="button">Generate 10 random numbers</button>Window: crypto property / notebook
Window: crypto property
Runnable notebook: every JavaScript, HTML and CSS example on this page executes in a sandboxed local frame. Nothing leaves the browser.
function genRandomNumbers() {
const array = new Uint32Array(10);
globalThis.crypto.getRandomValues(array);
const randText = document.getElementById("myRandText");
randText.textContent = `The random numbers are: ${array.join(" ")}`;
}
document.querySelector("button").addEventListener("click", genRandomNumbers);