// Secure random integer in [0, max):
function secureRandom(max) {
return crypto.getRandomValues(new Uint32Array(1))[0] % max
}Combine getRandomValues() with modulo to get a random integer in a range.
crypto.getRandomValues() works with various typed array types, including Uint32Array.
Challenge: Verify that getRandomValues can fill a Uint32Array and returns an array of length 2.