MDN self-hosted library · e01.org

Window: crypto property

Runnable notebook: every JavaScript, HTML and CSS example on this page executes in a sandboxed local frame. Nothing leaves the browser.

html
<p id="myRandText">The random numbers are:</p>
<button type="button">Generate 10 random numbers</button>
js
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);