JS Built-ins
cryptoadvanced

crypto β€” works with Uint32Array

πŸ“– Usage Example
// 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() β€” other typed array types

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.

πŸ’‘ Hints (1)
  • β€’ getRandomValues supports multiple typed array constructors