Secure Random Number Generator

Generate cryptographically secure random integers offline using the Web Crypto API. Customize range, duplicates, sorting, and formatting.

âš™ī¸ Generator Settings

📋 Generated Results

Design, Media & Web Assets • Technical Reference CSPRNG & Randomness in Modern Cryptography Guide

Working with Secure Random Number Generator? Read our architectural guide or browse all utilities in the Utilities & Productivity Hub.

Read Guide →

CSPRNG vs PRNG: The Mathematics of Computer Randomness

Generating genuine randomness in deterministic digital computers is one of the most challenging problems in computer science. Traditional pseudo-random number generators (PRNGs), such as the algorithms behind Math.random() in JavaScript or random.random() in Python, are completely deterministic mathematical formulas initialized by a seed value.

For scientific simulations, lottery draws, cryptographic key derivation, and statistical sampling, standard PRNGs are dangerous because an observer can predict future outputs after analyzing a small sequence of numbers. Cryptographically Secure Pseudo-Random Number Generators (CSPRNG) solve this by harvesting entropy from unpredictable physical hardware events (thermal sensor noise, atmospheric radio noise, disk I/O timings, and mouse movement jitter).

Our Random Number Generator harnesses the browser's native CSPRNG (crypto.getRandomValues) to generate statistically unbiased integer and decimal values within customizable min/max ranges.

Eliminating Modulo Bias in Random Range Selection

A subtle mathematical defect in naive random number generators is modulo bias. When mapping a 32-bit random integer (range 0 to 4,294,967,295) into a smaller range (like 1 to 10) using simple modulo arithmetic (rand % 10), numbers at the lower end of the range have a slightly higher probability of selection because 2^32 is not evenly divisible by 10.

Our algorithm implements rejection sampling (the Fisher-Yates approach), discarding values in the truncated remainder window to ensure mathematically perfect uniform distribution across all possible outcomes.

Programmatic CSPRNG Random Integers in JavaScript & Python

// Unbiased CSPRNG Random Integer between min and max (inclusive)
function secureRandomInt(min, max) {
  const range = max - min + 1;
  const maxSafe = Math.floor(0xFFFFFFFF / range) * range;
  const uint32 = new Uint32Array(1);

  let rand;
  do {
    window.crypto.getRandomValues(uint32);
    rand = uint32[0];
  } while (rand >= maxSafe); // Rejection sampling eliminates modulo bias

  return min + (rand % range);
}

console.log(secureRandomInt(1, 100));
# Python 3 secrets module
import secrets

# Generates unbiased random integer in range [min, max]
secure_int = secrets.randbelow(100) + 1 # 1 to 100
print("Random Int:", secure_int)

Bulk Sampling with or without Replacement

Our generator allows bulk output generation (up to 1,000 numbers at once) with options for with replacement (numbers can repeat, like rolling dice) or without replacement (unique numbers only, like drawing lottery balls or shuffling cards).

Related Utilities & Productivity

Chain Secure Random Number Generator with these complementary client-side utilities from our Utilities & Productivity collection:

Barcode Generator →

Generate custom barcodes online instantly. Supports CODE128, CODE39, EAN-13, UPC, ITF, and more. Customize colors, sizes, text visibility and download in SVG or PNG. 100% offline.

Aspect Ratio Calculator →

Calculate and scale aspect ratios easily. Simplify width and height into standard ratios (16:9, 4:3, 1:1), compute new scaled dimensions, and preview shapes visually. 100% offline.

Color Palette Generator →

Generate beautiful color palettes and schemes offline. Choose from analogous, monochromatic, complementary, and triadic rules. Lock colors, extract HEX/CSS/JSON codes, and copy instantly.

Text to Speech Reader →

Convert text to natural-sounding speech online. Adjust volume, pitch, speed, and select from multiple system voices. Uses native HTML5 Web Speech API. 100% offline.

Frequently Asked Questions

Yes. Because our tool relies on hardware-harvested CSPRNG entropy with rejection sampling, outputs satisfy rigorous statistical tests for randomness (NIST SP 800-22 and Dieharder test suites).

Yes. Simply toggle the "Unique Numbers (Without Replacement)" checkbox.

You can specify any integer range from -1,000,000,000 to +1,000,000,000.

Yes. The Web Crypto API functions fully without an internet connection.

No. Everything is computed directly in your browser.