Random Number Generator — Free Online Tool

Generate random numbers with custom min/max range, quantity, duplicates control, sorting. Cryptographically secure random. Export as CSV, JSON, text.

Use this free online Random Number Generator directly in your browser. No signup required, no data leaves your device. Part of Utilier — a collection of 133+ developer utilities.

What is Random Number Generator (RNG) with Range & Options?

Random number generator creates cryptographically secure random integers within a specified range (min to max). Set minimum (e.g., 1), maximum (e.g., 100), and quantity (how many numbers to generate). Options include: allow duplicates (same number can repeat), unique numbers only (no duplicates), sort ascending/descending/none. Useful for lottery numbers, dice rolls, password generation, random sampling, testing, or games. Uses Web Crypto API (window.crypto.getRandomValues) for secure randomness (better than Math.random for security-critical applications). Export results as CSV, JSON, or plain text.

  • Custom range (min/max): Set minimum (e.g., 1) and maximum (e.g., 100). Generates random integers between min and max (inclusive). Example: 1-100 = numbers like 1, 50, 99, 100.
  • Quantity control: Generate 1 to 10,000+ numbers at once. Useful for bulk testing, data generation, or statistical sampling.
  • Duplicates control: Allow duplicates (same number can repeat) or unique only (no duplicates). Unique mode useful for lottery (pick 6 unique numbers from 1-49).
  • Sorting options: Sort results: ascending (1, 2, 3...), descending (100, 99, 98...), or none (random order). Helpful for readability or analysis.
  • Cryptographically secure: Uses window.crypto.getRandomValues (Web Crypto API) for secure randomness. Not predictable (unlike Math.random). Suitable for passwords, tokens, security applications.

Why use random number?

Generating random numbers is common in programming, testing, games, and security. This tool provides secure, customizable random numbers instantly.

  • Avoid Math.random() bias: Math.random() is pseudo-random (predictable with seed knowledge). Crypto.getRandomValues is cryptographically secure (unpredictable). Use for passwords, tokens, security.
  • Lottery or raffle numbers: Generate unique lottery numbers (6 numbers from 1-49, no duplicates). Or raffle winners (pick 10 unique IDs from 1-1000).
  • Dice rolls and games: Simulate dice (1-6 for d6, 1-20 for d20), card draws, or random events in games. Example: damage roll (1-10), critical hit (1-100).
  • Testing and simulation: Generate test data (random ages 18-65, random prices 10-1000). Useful for unit tests, load testing, or data simulation.
  • Random sampling: Select random samples from a population (pick 100 random IDs from 1-10000 for survey). Useful for statistics or A/B testing.
  • Export for use: Export as CSV (for Excel), JSON (for code), or plain text (one per line). Copy to clipboard or download file.

When to use random number

Use whenever you need random numbers for any purpose.

  • Generating lottery numbers (6 unique numbers from 1-49, no duplicates).
  • Simulating dice rolls (d6 = 1-6, d20 = 1-20, d100 = 1-100) for games or RPGs.
  • Creating random passwords or PINs (4-digit PIN = 1000-9999, 6-digit = 100000-999999).
  • Testing software with random test data (ages, prices, quantities, IDs).
  • Random sampling for surveys or experiments (pick 100 random users from 1-10000).
  • Raffle or giveaway winners (pick 10 unique winners from 1-500 entries).
  • Generating random seeds for algorithms (machine learning, simulations, crypto).

How to use random number

Set range, quantity, options; click Generate.

  1. Set minimum value: Enter minimum number (e.g., 1, 0, -100). Minimum is inclusive (can be generated). Default: 1.
  2. Set maximum value: Enter maximum number (e.g., 100, 1000, 9999). Maximum is inclusive (can be generated). Default: 100.
  3. Set quantity: How many numbers to generate (1-10000+). Example: 6 for lottery, 100 for testing, 1000 for simulation.
  4. Choose duplicates option: Allow duplicates (same number can repeat) or Unique only (no duplicates). Unique fails if quantity > range (can't pick 100 unique numbers from 1-50).
  5. Select sorting (optional): None (random order), Ascending (1, 2, 3...), Descending (100, 99, 98...). Sorting helps readability.
  6. Click Generate: Tool generates random numbers using Web Crypto API. Results appear instantly (even for 10,000 numbers).
  7. Export or copy: Copy to clipboard, download as CSV (for Excel), JSON (for code), or plain text (one per line). Use in spreadsheets, code, or documents.

Key features

  • Custom range: Set min/max (1-100, 0-1000, -100 to 100). Inclusive range (min and max can be generated).
  • Bulk generation: Generate 1 to 10,000+ numbers at once. Fast (uses efficient algorithm).
  • Unique or duplicates: Unique mode prevents duplicates (lottery numbers). Duplicates allowed for dice rolls or testing.
  • Sorting options: Sort ascending, descending, or none. Helpful for analysis or presentation.
  • Cryptographically secure: Uses Web Crypto API (window.crypto.getRandomValues). Not predictable like Math.random.
  • Export formats: CSV, JSON, plain text. Copy to clipboard or download. Use in Excel, code, or documents.
  • Negative numbers: Supports negative ranges (-100 to 100, -10 to 10). Useful for temperature, coordinates, offsets.

Common use cases

  • Lottery numbers (6 from 1-49, unique): Min: 1, Max: 49, Quantity: 6, Unique: Yes, Sort: Ascending. Generates 6 unique numbers (e.g., 3, 12, 27, 35, 42, 48). No duplicates.
  • Dice roll (d20 for RPG): Min: 1, Max: 20, Quantity: 1, Duplicates: Allowed. Generates 1 number (1-20). Simulate d20 dice for D&D, Pathfinder, etc.
  • Random 4-digit PIN: Min: 1000, Max: 9999, Quantity: 1. Generates 4-digit PIN (e.g., 5472). For testing or weak password generation (not secure for real use, use random-string for passwords).
  • Testing data (100 random ages): Min: 18, Max: 65, Quantity: 100, Duplicates: Allowed. Generates 100 random ages for test data. Export as CSV for spreadsheet.
  • Random sampling (50 user IDs): Min: 1, Max: 10000, Quantity: 50, Unique: Yes. Picks 50 unique user IDs for survey or A/B test. No duplicates.
  • Raffle winners (10 from 500 entries): Min: 1, Max: 500, Quantity: 10, Unique: Yes, Sort: Ascending. Picks 10 unique winners. Fair and random (cryptographically secure).

Examples

Random number generation examples.

Lottery (6 unique from 1-49)

Min: 1, Max: 49, Quantity: 6, Unique: Yes, Sort: Ascending
[3, 12, 27, 35, 42, 48]

6 unique numbers, sorted. No duplicates. Common lottery format (6/49, Powerball uses 1-69).

Dice roll (d6)

Min: 1, Max: 6, Quantity: 1, Duplicates: Allowed
4

Simulates 6-sided dice (d6). Random number 1-6. For d20, use Min: 1, Max: 20.

Random ages (10 people)

Min: 18, Max: 65, Quantity: 10, Duplicates: Allowed
[25, 42, 19, 58, 33, 41, 22, 50, 36, 29]

10 random ages (18-65). Duplicates allowed (two people can be same age). Useful for test data.

Random 4-digit PIN

Min: 1000, Max: 9999, Quantity: 1
5472

4-digit PIN (1000-9999). For testing only (weak security). Use random-string tool for secure passwords.

Raffle winners (5 from 100)

Min: 1, Max: 100, Quantity: 5, Unique: Yes, Sort: Ascending
[7, 23, 51, 78, 92]

5 unique winners from 100 entries. Fair and random (cryptographically secure). No duplicates.

Technical reference

Random number generation specifications:

Algorithm
Uses Web Crypto API (window.crypto.getRandomValues). Cryptographically secure random (CSPRNG). Generates random bytes, then maps to range using rejection sampling (avoids modulo bias).
Range
Minimum (inclusive) to Maximum (inclusive). Example: 1-100 includes 1 and 100. Supports negative: -100 to 100. Max range: -2^31 to 2^31-1 (32-bit integers).
Duplicates mode
Allow duplicates: same number can repeat (useful for dice, testing). Unique: no duplicates (useful for lottery, sampling). Unique fails if quantity > range size.
Sorting
None (random order), Ascending (smallest to largest), Descending (largest to smallest). Applied after generation.
Quantity limit
1 to 10,000+ numbers. Browser limit ~1 million (memory). For unique mode, quantity ≤ range size (can't pick 100 unique from 1-50).
Bias prevention
Uses rejection sampling to avoid modulo bias. Example: Math.random() % 10 is biased (0-9 not equally likely). Rejection sampling ensures uniform distribution.
Export formats
CSV (comma-separated: 1,2,3), JSON (array: [1,2,3]), plain text (one per line: 1\n2\n3). Copy to clipboard or download file.
Math.random vs Crypto
Math.random() = pseudo-random (predictable with seed). Crypto.getRandomValues = cryptographically secure (unpredictable). Use Crypto for passwords, tokens, security.
Performance
Generates 10,000 numbers in <100ms. Uses efficient algorithm (O(n) for duplicates, O(n log n) for unique with sorting).
Browser support
Web Crypto API supported in all modern browsers (Chrome, Firefox, Safari, Edge). IE 11+ (with msCrypto fallback).

Common mistakes to avoid

Using Math.random() for security-critical applications (passwords, tokens)

Why it happens: Math.random() is pseudo-random (deterministic with known seed). Attackers can predict output if they know seed or previous values. Not suitable for passwords, tokens, or crypto. Common in old tutorials.

How to avoid it: Use window.crypto.getRandomValues (Web Crypto API) for security. Example: crypto.getRandomValues(new Uint32Array(1))[0]. Cryptographically secure (unpredictable).

Modulo bias (random % max) causing non-uniform distribution

Why it happens: Example: random(0-255) % 10 gives 0-9, but 0-5 appear more often (256 % 10 = 6 remainder). 0-5 appear 26 times, 6-9 appear 25 times. Bias in randomness.

How to avoid it: Use rejection sampling: generate random, reject if out of range, retry. Or use crypto.getRandomValues with proper mapping (this tool uses rejection sampling).

Requesting unique numbers > range size (100 unique from 1-50)

Why it happens: Impossible to pick 100 unique numbers from 1-50 (only 50 numbers available). Tool fails or hangs. Common when copy-pasting settings without checking.

How to avoid it: Ensure quantity ≤ range size for unique mode. Example: 6 unique from 1-49 (OK), 100 unique from 1-50 (FAIL). Tool should validate and show error.

Not seeding random for reproducible testing

Why it happens: Crypto.getRandomValues is unpredictable (good for security, bad for testing). Tests fail randomly if they depend on random values. Can't reproduce bugs.

How to avoid it: For testing, use seeded PRNG (pseudo-random with seed). Example: Math.random with seed (seedrandom.js), or use fixed values instead of random. Don't use Crypto for reproducible tests.

Generating negative ranges incorrectly (-10 to 10 gives wrong range)

Why it happens: Example: random % 20 gives 0-19, then subtract 10 = -10 to 9 (wrong, should be -10 to 10). Off-by-one error. Common when manually calculating range.

How to avoid it: Use range = max - min + 1, then random % range + min. Example: -10 to 10 = range 21, random % 21 + (-10) = -10 to 10. This tool handles negative ranges correctly.

Frequently asked questions

What is the difference between Math.random() and crypto.getRandomValues()?

Math.random() = pseudo-random (predictable with seed, not secure). crypto.getRandomValues() = cryptographically secure (unpredictable, secure for passwords/tokens). Use crypto for security.

Can I generate negative random numbers?

Yes. Set min and max to negative values. Example: -100 to 100 generates negative and positive numbers. Useful for coordinates, temperatures, offsets.

What happens if I request unique numbers > range size?

Error or failure. Can't pick 100 unique numbers from 1-50 (only 50 available). Tool should validate and show error. Reduce quantity or increase range.

How do I simulate dice rolls (d6, d20, d100)?

d6 (6-sided): Min 1, Max 6. d20 (20-sided): Min 1, Max 20. d100 (100-sided): Min 1, Max 100. Quantity 1 for single roll, or more for multiple rolls.

Is this random enough for cryptography or security?

Yes. Uses window.crypto.getRandomValues (Web Crypto API), which is cryptographically secure. Suitable for passwords, tokens, keys. NOT Math.random (not secure).

Can I export random numbers to Excel or CSV?

Yes. Click Export → CSV. Download file or copy to clipboard. Open in Excel, Google Sheets, or any spreadsheet software. Format: one number per line or comma-separated.

How do I generate random 4-digit or 6-digit PINs?

4-digit: Min 1000, Max 9999. 6-digit: Min 100000, Max 999999. Quantity 1. For secure passwords, use random-string tool (letters, numbers, symbols).

References

Privacy and availability

  • Runs entirely in your browser — zero server processing
  • No signup or account required
  • Works offline once loaded
  • Fast, lightweight, no external dependencies
  • Available as a browser extension for Chrome and Firefox