随机数:抽奖唯一性与随机源
在任意范围内生成随机整数或小数,支持批量生成和不重复模式。
随机数:抽奖唯一性与随机源
涉奖、涉密场景优先使用加密随机;模拟场景可用普通随机。开启不重复可避免同一批抽奖出现重复号码。
合规审计可能需要第三方见证,本页为便民工具。
How the numbers are generated
Each number comes from your browser’s cryptographically secure generator (crypto.getRandomValues), the same source used to create encryption keys. It is unpredictable even to someone who has seen every earlier result, and it is never seeded from the clock.
Turning random bits into a number in your range is where many generators go subtly wrong. Taking a 32-bit random value modulo the range size makes low numbers slightly more likely whenever the range does not divide 2³² evenly. This tool uses rejection sampling instead: draws that would fall into that uneven tail are discarded and redrawn, so every integer between your minimum and maximum has exactly the same probability. Ranges wider than 2³² combine two draws into a 53-bit value, the largest whole number JavaScript represents exactly.
Results are whole numbers. If you type decimal bounds they are rounded inward — a range of 1.5 to 9.9 draws from 2 to 9 — so the result can never fall outside what you entered.
Duplicates allowed vs unique numbers only
With duplicates allowed, every draw is independent, like rolling a die several times — repeats are expected and are not a sign of a broken generator. Repeats arrive sooner than most people expect: drawing 10 numbers from 1–100 has a 37% chance of at least one repeat, and drawing 23 numbers from 1–365 crosses 50% (the classic “birthday problem”).
With “unique numbers only” ticked, the tool draws without replacement, like pulling tickets from a hat. For ranges up to 100,000 it shuffles the whole range with a Fisher–Yates shuffle and takes the first N values; for larger ranges it draws and skips any value it has already picked. Either way, the order of the results is itself random.
Worked examples
- Dice: 1 to 6 for a standard die, 1 to 20 for a d20. Set “how many” to the number of dice and leave duplicates allowed — two dice can show the same face.
- Raffle with 250 numbered tickets and 3 prizes: minimum 1, maximum 250, generate 3, unique only. Draw all prizes in one click so no ticket can win twice.
- Lottery-style pick (6 from 49): minimum 1, maximum 49, generate 6, unique only, then sort the numbers yourself if you want them in order.
- Random spreadsheet row: if your data starts on row 2 and ends on row 1,001, use 2 to 1,001 so the header row can never be chosen.
- Splitting 30 people into teams: number everyone 1–30, generate 30 unique numbers, and assign the first 10 results to team A, the next 10 to team B, and so on.
Running a fair public draw
The generator is fair, but a draw also has to be seen to be fair. Agree the range and the number of winners before drawing, run the draw once on screen or on a recorded call, and do not redraw because of an unwelcome result. Publish the settings (range, count, unique or not) alongside the winning numbers.
The tool keeps no log and stores nothing, which protects privacy but means it cannot later prove what was drawn. Sweepstakes and promotions governed by law in some countries require an independently audited draw; use a regulated provider for those.
Limits
- Up to 1,000 numbers per click.
- Bounds can be any whole numbers within about ±9 quadrillion (±2⁵³ − 1).
- In unique mode, “how many” cannot exceed the size of the range — you cannot pick 11 distinct numbers from 1–10.
Related tools
These free tools pair well with this page — open them in a new tab to finish your workflow.
常见问题
这是真正的随机数吗?
此工具使用window.crypto.getRandomValues(),即浏览器的密码学安全随机数生成器。适用于安全敏感应用,如生成彩票号码、随机密钥或随机数。与 Math.random() 不同,它无法根据已生成的结果推测下一个值。
PRNG和CSPRNG有什么区别?
PRNG(伪随机数生成器)使用以某个值为种子的确定性算法;相同种子会产生相同序列。CSPRNG(密码学安全PRNG)即使知道之前的输出也无法预测。此工具使用CSPRNG。
可以生成相同的数字两次吗?
可以。每个数字都以相等概率独立抽取,不保证唯一性。如果需要唯一数字,可以批量生成后去除重复,或使用洗牌/排列方法。
我可以使用的最大范围是多少?
此工具支持JavaScript安全整数范围内的整数(最大2^53 - 1)。范围内每个值的概率完全相同:内部采用拒绝采样避免取模偏差,超过 2^32 的范围会合并两次 32 位随机数。
如何模拟掷骰子?
将范围设置为1-6模拟标准六面骰。其他骰子:1-4为d4,1-8为d8,1-10为d10,1-12为d12,1-20为d20(桌游RPG中常用)。