这一页公开幸运抽奖用到的全部材料:抽奖名单、开奖种子和抽签算法。页面打开时,你的浏览器已经用这些材料从头算了一遍,下方会显示算出的结果和公布的名单是否一致。
人气作品的 2 位得主不进入抽奖。其余参与者每人一签,不论投稿几篇;编号按每人首次投稿的时间先后排列。右侧数字是计入活动的投稿篇数(每人最多 3 篇)。
SHA-256(名单指纹 + 换行 + 种子 + 换行 + 序号),序号从 0 开始。每个结果是 64 位十六进制,切成 8 段,每段当作一个 32 位整数,按顺序使用。(随机数 mod 剩余人数) + 1 位,抽中的人移出名单。随机数落在不能整除的尾段时丢掉重取,保证每个人的机会完全相等。同样的名单和种子,任何人在任何电脑上算出的结果都完全一样。名单的编号规则、抽奖顺序和算法都写在本页,结果由它们唯一决定。种子是公开的彩票号码,可以在福彩官网或各大彩票网站按期号查到。
const K = new Uint32Array([
0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2,
]);
function sha256(text) {
const bytes = new TextEncoder().encode(text);
const len = Math.ceil((bytes.length + 9) / 64) * 64;
const msg = new Uint8Array(len);
msg.set(bytes);
msg[bytes.length] = 0x80;
const view = new DataView(msg.buffer);
view.setUint32(len - 8, Math.floor(bytes.length / 0x20000000));
view.setUint32(len - 4, (bytes.length * 8) >>> 0);
const h = new Uint32Array([0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19]);
const w = new Uint32Array(64);
const rot = (x, n) => (x >>> n) | (x << (32 - n));
for (let off = 0; off < len; off += 64) {
for (let i = 0; i < 16; i++) w[i] = view.getUint32(off + i * 4);
for (let i = 16; i < 64; i++) {
const s0 = rot(w[i - 15], 7) ^ rot(w[i - 15], 18) ^ (w[i - 15] >>> 3);
const s1 = rot(w[i - 2], 17) ^ rot(w[i - 2], 19) ^ (w[i - 2] >>> 10);
w[i] = w[i - 16] + s0 + w[i - 7] + s1;
}
let [a, b, c, d, e, f, g, hh] = h;
for (let i = 0; i < 64; i++) {
const t1 = (hh + (rot(e, 6) ^ rot(e, 11) ^ rot(e, 25)) + ((e & f) ^ (~e & g)) + K[i] + w[i]) >>> 0;
const t2 = ((rot(a, 2) ^ rot(a, 13) ^ rot(a, 22)) + ((a & b) ^ (a & c) ^ (b & c))) >>> 0;
hh = g; g = f; f = e; e = (d + t1) >>> 0; d = c; c = b; b = a; a = (t1 + t2) >>> 0;
}
h[0] += a; h[1] += b; h[2] += c; h[3] += d; h[4] += e; h[5] += f; h[6] += g; h[7] += hh;
}
return Array.from(h, x => x.toString(16).padStart(8, '0')).join('');
}
/** 键名排序、无空白的 JSON,用来计算指纹(公示文件怎么排版都不影响结果)。 */
function canonical(v) {
if (Array.isArray(v)) return '[' + v.map(canonical).join(',') + ']';
if (v && typeof v === 'object') return '{' + Object.keys(v).sort().map(k => JSON.stringify(k) + ':' + canonical(v[k])).join(',') + '}';
return JSON.stringify(v);
}
const poolHash = pool => sha256(canonical(pool));
/** 种子统一全半角、去掉首尾空白、连续空白合并为一个空格。 */
const normalizeSeed = s => String(s ?? '').normalize('NFKC').trim().replace(/\s+/g, ' ');
/**
* 开奖。随机数来自 SHA-256(指纹 + "\n" + 种子 + "\n" + 序号),每个摘要切成 8 个 32 位整数依次使用;
* 每抽一人,从剩余名单(按编号排列)中取第 (数值 mod 剩余人数) + 1 位,数值落在不能整除的尾段时跳过以免偏差。
* 奖项按公示顺序抽取,已中奖者移出名单。
*/
function draw(pool, seed) {
const hash = poolHash(pool);
const s = normalizeSeed(seed);
if (!s) throw new Error('请填写开奖种子');
let counter = 0;
const buffer = [];
const nextWord = () => {
if (!buffer.length) {
const digest = sha256(`${hash}\n${s}\n${counter++}`);
for (let i = 0; i < 64; i += 8) buffer.push(parseInt(digest.slice(i, i + 8), 16));
}
return buffer.shift();
};
const below = n => {
const limit = Math.floor(0x100000000 / n) * n;
for (;;) {
const x = nextWord();
if (x < limit) return x % n;
}
};
const remaining = pool.entrants.slice().sort((a, b) => a.no - b.no);
const awards = pool.prizes.map(prize => {
const winners = [];
while (winners.length < prize.count && remaining.length) winners.push(remaining.splice(below(remaining.length), 1)[0]);
return { ...prize, winners, short: prize.count - winners.length };
});
return { poolHash: hash, seed: s, awards, notDrawn: remaining };
}