Cryptographically Secure RNG
Generate unbiased random integers using the browser Web Crypto API. Features rejection sampling, unique non-repeating sets, sorting, and live entropy metrics.
Generator Parameters
CSPRNG ActiveEntropy, Modulo Bias & CSPRNG: A Cryptographic Engineering Deep Dive
Random number generation is one of the most critical yet misunderstood pillars of modern computer science. From public-key cryptography (RSA, ECC), session identifiers, and password salting to lottery ticket allocation, randomized clinical trials, and scientific Monte Carlo integration, software systems require sequences of numbers that are both uniformly distributed and inherently unpredictable.
However, digital computers are deterministic state machines: given identical inputs and instructions, they produce identical outputs. Generating genuine randomness on a deterministic CPU requires careful architectural coordination between hardware thermal noise, operating system entropy estimators, and unbiased rejection sampling algorithms.
1. PRNG vs. CSPRNG: The Vulnerabilities of Math.random()
Standard software development typically reaches for JavaScript's Math.random(), Python's random module, or C's rand(). These are Pseudo-Random Number Generators (PRNGs).
Linear & Shift-Register PRNGs (Non-Cryptographic)
Under the hood, modern V8 (Google Chrome, Node.js) implements the Xoroshiro128+ algorithm for Math.random(). While it evaluates in less than 2 nanoseconds per call, its internal state consists of only two 64-bit unsigned integers ($128$ bits total).
Because every output is a deterministic linear transformation of previous states, an adversary who observes just a handful of sequential numbers can solve the linear system of equations, recover the internal 128-bit state vector, and predict every subsequent random number or reverse engineer past numbers. Using Math.random() for password reset tokens, session cookies, or gaming giveaways creates severe security vulnerabilities.
Cryptographically Secure Pseudorandom Number Generators (CSPRNG)
A CSPRNG must satisfy two rigorous mathematical criteria defined by cryptographer Andrew Yao:
- Next-Bit Unpredictability: Given the first $k$ bits of a random sequence, no polynomial-time algorithm can predict the $(k+1)$-th bit with probability greater than $0.5 + \epsilon$.
- State Compromise Resistance (Forward & Backward Secrecy): If an attacker learns the generator's internal state at time $t$, they cannot reconstruct past states ($t - 1$) or predict future states ($t + 1$) because the system continuously injects fresh external physical entropy.
Our tool interfaces directly with window.crypto.getRandomValues(), which calls down to kernel-level CSPRNG implementations: /dev/urandom on Linux/Android, getentropy() on macOS/iOS, and BCryptGenRandom on Windows.
2. The Modulo Bias Trap and Rejection Sampling
Generating a random integer between $1$ and $N$ from an unbiased 32-bit random integer generator ($[0, 2^{32} - 1]$) is frequently done incorrectly:
The Flawed Modulo Technique
result = min + (cryptoRandomInt % (max - min + 1)); // FLAWED & BIASED
To understand why this introduces statistical bias, consider an artificial 8-bit generator that produces uniform integers from $0$ to $255$ ($256$ total states), and suppose we want a random number from $0$ to $9$ ($10$ possible outcomes):
- $256 / 10 = 25$ with a remainder of $6$.
- The numbers $0, 1, 2, 3, 4, 5$ are produced by $26$ different values in the byte range ($0, 10, 20, \dots, 250$).
- The numbers $6, 7, 8, 9$ are produced by only $25$ different values ($6, 16, 26, \dots, 246$).
- The probability of landing on $0$ through $5$ is $26 / 256 \approx 10.156\%$.
- The probability of landing on $6$ through $9$ is $25 / 256 \approx 9.765\%$.
This discrepancy is modulo bias. In lotteries, cryptography, or scientific simulations, this subtle statistical skew invalidates results and introduces exploitable patterns.
The Solution: Exact Rejection Sampling
To achieve absolute uniformity, our generator computes the largest multiple of the range that fits within $2^{32}$, and discards (rejects) any generated number that falls in the incomplete remainder zone:
Unbiased Rejection Sampling Mathematical Threshold
Limit = 2^32 - (2^32 mod Range)
If rand ≥ Limit, reject and sample again; else return min + (rand mod Range)
Because the active sample space is an exact integer multiple of the target range, every outcome has an identically equal probability down to the last decimal place.
3. Sampling Without Replacement: Fisher-Yates Shuffle
When generating unique random sequences (such as lottery draws, seating charts, or card shuffles), naive implementations repeatedly generate numbers and check array.includes(). This approach degrades asymptotically to $O(N^2)$ or worse as the pool fills, resulting in severe browser freezing when sampling large sets.
Instead, 2ClickKit implements the modern Fisher-Yates (Knuth) partial shuffle algorithm with CSPRNG entropy:
Cryptographic Partial Fisher-Yates Algorithm in TypeScript
// Client-side in-browser execution The Durstenfeld variant operates in optimal $O(K)$ time where $K$ is the number of items drawn, visiting each slot exactly once with zero bias and zero unnecessary iterations.
4. Statistical Testing: Chi-Squared ($\chi^2$) Goodness-of-Fit and Shannon Entropy
How can an engineer verify that a random number generator is genuinely uniform? Two universal benchmarks are Shannon Entropy and the Pearson Chi-Squared ($\chi^2$) Test.
1. Shannon Information Entropy
H(X) = - ∑_(i=1)^(K) p(x_i) × log_2(p(x_i))
For a perfectly uniform discrete random variable over $K$ outcomes, $p(x_i) = 1/K$, yielding maximum theoretical entropy: $H_{max} = \log_2(K)$ bits. If any state repeats disproportionately, entropy drops below this theoretical ceiling.
2. Pearson Chi-Squared Goodness-of-Fit Test
χ^2 = ∑_(i=1)^(K) [ (Observed_i - Expected_i)^2 / Expected_i ]
For $N$ total samples divided across $K$ equal bins, the expected frequency per bin is $E_i = N / K$. A calculated $\chi^2$ statistic matching the theoretical critical value for $K - 1$ degrees of freedom confirms that fluctuations represent natural Poissonian variance rather than algorithmic bias.
5. Comparison Table: Random Number Generation Techniques
| Method | Source Mechanism | Crypto Secure? | Execution Location | Best Use Case |
|---|---|---|---|---|
| Web Crypto CSPRNG (Our Tool) | OS Kernel Entropy Pool + Rejection Sampling | Yes (CSPRNG) | 100% In-Browser | Lotteries, PINs, Cryptographic keys, Audits |
| JavaScript Math.random() | Xoroshiro128+ PRNG | No (Predictable) | 100% In-Browser | Fast animations, visual particle noise |
| Linux /dev/urandom | ChaCha20 over OS interrupt noise | Yes (CSPRNG) | OS Kernel / Local Server | SSH keys, TLS certificates, Linux sysadmin |
| Hardware TRNG (RDRAND) | Thermal Johnson noise in CPU silicon | Yes (Physical TRNG) | Hardware Microcode | Seeding OS kernel entropy pools |
100% In-Browser Privacy Protection
Generating sensitive tokens, raffle winners, or PIN combinations on remote servers risks logging or interception over public networks. 2ClickKit generates all random numbers locally inside your browser's dedicated JavaScript V8 thread. Zero numbers, parameters, or IP records are ever transmitted to any external server.
How to Use Cryptographically Secure RNG
-
Define Min and Max Value Bounds
Set custom integer boundaries, including zero, negative numbers, or large integer ranges up to billions.
-
Select Quantity and Uniqueness
Specify how many numbers to generate (1 to 10,000) and toggle whether to sample with or without replacement.
-
Choose Sorting and Formatting
Sort values ascending, descending, or keep generation order; format output as comma-separated, line-by-line, or JSON.
-
Analyze Entropy & Export
Inspect live Shannon entropy, mean, median, standard deviation, and download your dataset as .TXT or .CSV.
Lottery 6/49 Quick Pick Example
Min: 1, Max: 49, Count: 6, Unique (No Duplicates), Ascending 7, 14, 22, 31, 38, 45 (Shannon Entropy: 2.585 bits) Sampled without replacement via cryptographic partial Fisher-Yates shuffle.
Technical Specifications
- Supported Inputs: Comma-Separated Values, Line-by-Line (One per row), Space-Separated, JSON Array
- Input Limit: Up to 10,000 numbers per single generation run
- Processing Engine: 100% In-Browser (Web Crypto API CSPRNG & Rejection Sampling)
- Content Uploads: None (Your files and text are processed locally on your device with zero uploads)
Privacy & Security Guarantee
Your Cryptographically secure integer sets are processed entirely in your web browser's memory using native client-side web technologies. Unlike traditional cloud tools, your content is never uploaded to remote servers, stored on external disks, or analyzed by third parties.
2ClickKit In-Browser vs Traditional Cloud Tools
| Feature | 2ClickKit (In-Browser) | Traditional Cloud Services |
|---|---|---|
| Data Privacy | Files never leave your local device | Uploaded to remote servers and third-party clouds |
| Processing Speed | Instant local execution (0ms upload time) | Constrained by internet upload & server processing queues |
| Account & Costs | 100% Free with zero registration or paywalls | Tiered subscriptions, limits, or forced sign-ups |
Best Practices & Tips
- For security tokens, PINs, or raffle drawings, always use CSPRNG generators to prevent algorithmic predictability.
- When generating lottery picks, toggle "Allow Duplicates" off to ensure every drawn number in your ticket is strictly unique.
- Export generated sets in JSON format for instant ingestion into automated testing pipelines, mock databases, or REST APIs.
- Observe the distribution histogram to visually confirm that large sample sizes distribute evenly across all interval bins.
Frequently Asked Questions
What makes this random number generator cryptographically secure?
Unlike standard generators that use deterministic pseudo-random formulas like Math.random(), our tool uses the Web Crypto API (window.crypto.getRandomValues). This interfaces directly with your operating system's kernel entropy pool (such as /dev/urandom on Unix/macOS or CryptGenRandom/CNG on Windows), providing true cryptographically secure pseudorandomness (CSPRNG).
What is modulo bias and how is it prevented here?
Modulo bias occurs when mapping a large integer range (like 0 to 2^32 - 1) onto an arbitrary range using the modulo operator (%), because 2^32 is rarely evenly divisible by the target range. Our algorithm uses rejection sampling to discard the uneven upper sliver of values, guaranteeing an exact, unbiased uniform distribution across every possible integer.
Can I generate unique lottery numbers without duplicates?
Yes! By turning off 'Allow Duplicates', the generator samples without replacement using an unbiased cryptographic Fisher-Yates partial shuffle algorithm. You can quickly select presets for popular lotteries like 6/49 or Powerball.
Why should I avoid Math.random() for security or cryptography?
Math.random() implementations (such as V8's Xoroshiro128+) are non-cryptographic PRNGs designed solely for raw speed. If an attacker observes approximately 2 to 3 consecutive floating-point outputs, they can reconstruct internal state matrices and predict all past and future numbers with 100% accuracy.
How is Shannon Entropy calculated for the generated numbers?
Shannon Entropy measures the average information density and unpredictability of the dataset in bits per value: H = -sum(p_i * log2(p_i)). For a truly uniform distribution across N unique values, entropy reaches its theoretical maximum of log2(N) bits.
Are any generated numbers logged or sent to remote servers?
Never. All cryptographic entropy generation, statistical analysis, array sorting, and file export formatting occur 100% inside your browser's local memory. Zero digits or parameters are transmitted over the network.
Can this tool generate negative numbers and zero?
Yes. You can specify negative integers for both minimum and maximum boundaries (e.g. -50 to +50 or -1,000 to -1). The generator handles sign offsets and ranges seamlessly without arithmetic distortion.