About this tool
Cryptographically Secure Random Number Generation (CSPRNG) powers enterprise prize raffles, classroom roll calls, statistical Monte Carlo sampling, and cryptographic entropy seeding. Standard JavaScript `Math.random()` uses deterministic PRNG algorithms (xorshift128+) whose internal states can be reverse-engineered, failing fairness and security audits. This tool leverages the browser's hardware-backed Web Crypto API (`crypto.getRandomValues`) to produce truly unpredictable integers across custom ranges, with optional duplicate exclusion and sorting.
How to Use This Tool (Step-by-Step)
Set Minimum & Maximum Bounds
Specify your integer bounds: Minimum and Maximum thresholds (e.g., 1 to 100). Supports negative and large numbers.
Configure Quantity & Uniqueness
Select how many numbers to generate and toggle 'Allow Duplicates' vs 'Unique Numbers Only' for raffle draws.
Generate & Copy Random Numbers
Click 'Generate' to obtain unbiased results. Sort outcomes ascending or copy as comma-separated values instantly.
Hardware-Backed Web Crypto CSPRNG
Powered by browser-native `crypto.getRandomValues()`, collecting hardware physical entropy to guarantee mathematical unpredictability.
Zero Modulo Bias Uniform Distribution
Eliminates subtle modulo bias via rejection sampling, ensuring every integer in your target range has mathematically identical probability.
100% Client-Side Air-Gapped
Draws execute 100% inside local device memory with zero server calls. Proves absolute integrity for public raffles.
Raffle Integrity & Sampling Gotchas
- •Run public corporate raffles on big screens: Because this tool runs locally with zero backend requests, projecting it live eliminates accusations of rigged APIs.
- •Pigeonhole principle in unique sampling: You cannot request more unique numbers than the span of the range (e.g., picking 15 unique numbers between 1 and 10).
- •Random numbers do not boost lottery odds: Every combination has identical mathematical probability. Play responsibly.
Code & Transformation Examples
Common Random Range Presets Benchmark
• 经典六面骰子 (D6) : 1 到 6 (允许重复)
• 课堂/会议随机抽学号 : 1 到 50 (排重不重复)
• 百分比检定骰子 (D100) : 1 到 100 (生成 1 个)
• 双色球红球号码 (6个) : 1 到 33 (强制不重复,抽取 6 个)
• 大乐透前区号码 (5个) : 1 到 35 (强制不重复,抽取 5 个)每一次生成的数字序列彼此完全独立(Independent and Identically Distributed, i.i.d),连续抛出 10 次正面硬币后,第 11 次正反面的概率依然严格是 50% 对 50%!* Independent random draws have no memory; past outcomes never influence future probabilities.
JavaScript Hardware CSPRNG Implementation Snippet
function getSecureRandomInt(min, max) {
const range = max - min + 1;
const maxValid = Math.floor(0xFFFFFFFF / range) * range;
const buffer = new Uint32Array(1);
do {
window.crypto.getRandomValues(buffer);
} while (buffer[0] >= maxValid); // 拒绝采样彻底消除模数偏差
return min + (buffer[0] % range);
}Math.random() 属于伪随机发生器(PRNG),攻击者在观察到若干连续输出后,可在数秒内逆向还原出内部种子(Seed),从而预测出后续的全部数字!* Financial draws and token selections strictly mandate `crypto.getRandomValues()`.
Frequently Asked Questions
Q: What is Modulo Bias and why is naive modulo flawed?
A: When maximum integer ranges do not divide evenly by your target span, simple modulo causes lower numbers to occur slightly more often. Rejection sampling fixes this.
Q: Does random generation work offline without internet?
A: Yes. Web Crypto draws hardware entropy directly from your local OS and CPU timers. It operates with full cryptographic integrity even in Airplane Mode.
Q: Will generating 10,000 numbers freeze my browser?
A: Not at all. Powered by native TypedArrays (`Uint32Array`), generating 10,000 random integers takes less than 5 milliseconds.