首页 通用效率工具内容详情

Random Number Generator: 1 to 10000 Picks, Unique, Sorted, No Modulo Bias - Curtain up, balls drop, spacebar redraws

2026-11-17 3 访客
Random Number Generator: 1 to 10000 Picks, Unique, Sorted, No Modulo Bias

站点名称:Random Number Generator: 1 to 10000 Picks, Unique, Sorted, No Modulo Bias

所属分类:通用效率工具

官方网址:https://www.9314.cn/tools/random-number/en/

SEO查询: 爱站网 站长工具

进入网站

站点介绍

Random Number Generator: 1 to 10000 Picks, Unique, Sorted, No Modulo Bias

Our office party raffle broke in the most predictable way: the tool on the big screen could only produce one number at a time, so the poor host had to click three times for the three third-prize winners while everyone waited. I went home and built the version she actually needed - one that draws everything in a single click, and quietly fixes the biases nobody notices until they matter.

The short version

  • Draw 1 to 10000 numbers in any range - integers or up to 6 decimal places, negatives like -10 to 10 typed straight in. The 10000 cap is a speed limit that tells you so instead of freezing the tab.
  • The random source is crypto.getRandomValues with rejection sampling. Math.random() taken modulo a range has a subtle bias (numbers in the uneven remainder come up slightly more often); here, values falling in that tail are thrown away and redrawn, so every number has exactly equal odds.
  • Unique mode checks capacity before promising anything: 11 unique picks from 1 to 10 is mathematically impossible, and the tool says "range too small" instead of quietly handing you duplicates. Decimal mode multiplies capacity by 10^places.
  • Raffles get a big-number mode - one huge digit on stage, spacebar redraws, projector-ready. Your last 10 draws stay on this device, reviewable, restorable, wipeable.

Why the fuss about rejection sampling

Most online RNG cores are Math.random modulo the range: take a pseudo-random float, multiply by the span, floor it. Two problems. The generator's seed is predictable. And the modulo introduces modulo bias: when 2^32 doesn't divide evenly by your span, the numbers in the remainder slice come up slightly more often - and in a giveaway, "slightly" is exactly where fairness cracks.

The fix here is rejection sampling: compute how many whole buckets your span divides into, and throw away any random value landing in the uneven tail, redrawing until it lands clean. The cost is a few extra random draws; the payoff is strictly equal probability for every number. Day to day you cannot tell the difference. At the grand prize draw, that difference is the whole story.

Four everyday plays

Lottery picks: the link ?min=1&max=49&n=6&uniq=1&sort=asc is a complete lotto setup - one click, six unique numbers in ascending order. Office raffle: big-number mode, staff ID range in, spacebar once per winner. Survey sampling: 1 to 5000, draw 50, unique and sorted, copy, done. Mock data: 6 decimal places, a thousand values, download the .txt and feed it to your program.

Why history only keeps 10 draws

The most common raffle dispute is "the range was 1 to 200 last time, I'm sure of it." Keeping the last 10 draws locally - parameters plus result summaries with mean and min/max - settles that argument in one glance. It stops at 10 because this is not a ledger: for disputes that matter, you should have recorded your screen at the time, and browser storage will not win you a lawsuit. The FAQ says this out loud too.

FAQ

Can I use this for raffles and giveaways? Is it legally notarized?

The randomness itself is up to the job: a crypto-grade random source plus rejection sampling gives every number exactly equal odds, which is more than fair enough for office parties, classroom draws, and community giveaways. What it does not have is third-party notarization - the page runs locally in your browser, so there is no way to prove to a notary that nobody touched the settings at the moment of the draw. For public commercial giveaways, record your screen (range, count, and the click itself) as evidence; for anything with legal stakes, use a notarized or regulator-approved drawing service.

How is this different from Math.random()?

Math.random() is a predictable pseudo-random generator - fine for jitter animations, wrong for raffles. Worse, taking Math.random() modulo a range introduces modulo bias: when the range does not divide evenly into the generator's output space, some numbers come up slightly more often than others. This tool uses crypto.getRandomValues (the browser's crypto-grade source) with rejection sampling: random values that fall in the uneven tail are thrown away and redrawn, so every number has exactly equal probability. You will not notice the difference day to day, but in a giveaway that difference is the whole fairness story.

Can it generate decimals? How many places?

Yes. Pick 0 to 6 decimal places: 0 means integers, 2 fits money amounts, 6 works for mock datasets. The generator draws uniformly in the integer domain first, then scales down by a power of ten - so decimals are just as uniform across the range as integers, not integers with random digits glued on.

Why does unique mode complain the range is too small?

Unique draws require the range to hold at least as many values as you asked for: 1 to 10 contains only 10 integers, so 11 unique picks is mathematically impossible. The tool checks this up front and tells you to widen the range or lower the count - it never quietly hands you duplicates. With decimals, capacity scales by 10^places (1 to 10 at 2 decimals offers 901 distinct values).

Where is the history stored? Does it pile up?

In your browser's localStorage on this device - never uploaded. Only the last 10 draws are kept, older ones get pushed out automatically, and parameters plus result summaries typically stay under 20KB total. Switch devices or clear site data and it is gone; the Clear my data link in the footer wipes it in one click, and in private browsing it vanishes when the window closes.

Does it work with negative ranges like -10 to 10?

Yes. Both bounds accept negatives - type or paste the minus sign like any other character. The tool works from the span (-10 to 10 spans 21 integers). For the [-1, 1) style ranges common in simulations, enter -1 to 0 as a close approximation.

中文版:https://www.9314.cn/tools/random-number/

 暂无评论,快来抢沙发吧~

发布评论