TOOL / 05
公平 抽奖系统
使用密码学安全随机数抽取,每位尚未中奖的参与者拥有相同机会。名单与奖品图片仅在当前浏览器中处理。
系统会自动去除空白和重复姓名;重新加载名单会清空当前抽奖结果。
幸运参与者
抽奖结果
公平说明:系统通过 Web Crypto 随机数与拒绝采样生成无偏随机索引;每轮从尚未中奖者中无放回抽取。
一、怎么用
- 把参与者名单粘进左侧文本框,每行一个姓名,也支持逗号、分号、制表符分隔(从 Excel 直接复制过来即可);
- 填写当前奖项(如"三等奖")、奖品名称和本次抽取人数,需要的话上传一张奖品图片;
- 点「加载名单」,系统会去空白、去重,并显示有效人数;
- 点「开始抽奖」,每轮从尚未中奖的人里抽,抽中的人不会再次出现;
- 抽完点「下载 CSV」,得到带姓名、奖项、时间的记录文件。
二、"公平"具体指什么
抽奖程序最容易出的问题不是"有人作弊",而是随机数不够随机。很多实现用 Math.random(),它速度快,但不是密码学安全的,理论上可被预测;而且直接用"随机数对人数取余"会带来模偏差——当随机数范围不能被人数整除时,靠前的几个位置被抽中的概率会略高。
本工具的做法是:
- 用浏览器提供的
crypto.getRandomValues()取密码学安全随机数; - 用拒绝采样(落在无效区间的随机数丢弃重取)消除模偏差,保证每个人概率完全相等;
- 无放回抽取,每轮从剩余名单里选,避免同一个人重复中奖。
三、办活动时的几个实用建议
- 先公示名单再开抽。把"加载名单"后显示的有效人数报给现场或群里,大家才知道基数是多少、有没有人被漏掉。
- 留下记录。抽完立刻下载 CSV,连同屏幕录制或截图一起存档,事后有争议时可复核。
- 重名要提前处理。系统按姓名去重,两个同名的人会被合并成一条。建议在名单里加上部门或编号后缀。
- 奖品图片只在本机读取。上传的图片不会发到服务器,仅用于展示。
四、适用与不适用
它适合公司年会、社群活动、课堂提问这类"现场公开抽取"的场景。如果活动涉及法定有奖销售、需要公证或需要向监管部门报备,请按当地规定执行,本工具只能作为现场的辅助展示手段。
How to use it
- Paste the participant list into the left box — one name per line, or comma, semicolon or tab separated (pasting straight from a spreadsheet works);
- Fill in the prize tier, the prize name and how many winners this round draws; optionally attach a prize image;
- Press Load list: blanks are trimmed, duplicates removed, and the effective count is shown;
- Press Start. Each round draws from people who have not won yet — nobody is picked twice;
- Press Download CSV for a record with names, prizes and timestamps.
What fair means here
The usual failure in a raffle script is not cheating, it is weak randomness. Many implementations use Math.random(): fast, but not cryptographically secure and theoretically predictable. Worse, taking a random number modulo the participant count introduces modulo bias — when the range is not a multiple of the count, the first few positions are slightly more likely.
This tool instead:
- draws from
crypto.getRandomValues(), the browser's cryptographically secure generator; - uses rejection sampling — discarding and redrawing values outside the valid range — to remove modulo bias, so every person has an identical chance;
- draws without replacement, so the same person cannot win twice.
Practical tips for running an event
- Announce the list first. Read out the effective count after loading, so the audience knows the pool size and that nobody was dropped.
- Keep a record. Download the CSV immediately and archive it with a screen recording or screenshot, in case of a dispute later.
- Handle duplicate names. The tool de-duplicates by name, so two people called the same thing collapse into one. Add a department or ID suffix in the list.
- Prize images stay local. Uploaded images are never sent anywhere; they are only displayed.
Scope
It fits live public draws: company parties, community events, classroom quizzes. If an activity is a regulated promotion requiring notarisation or regulatory filing, follow local rules — this tool can only serve as an on-stage display aid.