Skip to content

Instantly share code, notes, and snippets.


Block or report user

Report or block tonyofbyteball

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
tonyofbyteball / draw-winner-selection-algo.js
Last active Jan 6, 2019
Provably fair algorithm of selecting the winner based on bitcoin hash
View draw-winner-selection-algo.js
// bitcoin_hash is the hash (in hex) of the latest Bitcoin block
// arrPoints is array of points of all addresses ordered by address [{address: "...", points: 1234}, ...]
// rows1 is array of balances of all addresses ordered by address [{address: "...", balance: 1234}, ...]
// sum is the sum of all points
// 1. winner by points
let hash = crypto.createHash('sha256').update(bitcoin_hash).digest('hex');
let number = new BigNumber(hash, 16);
let random = (number.div(new BigNumber(2).pow(256))).times(sum);
You can’t perform that action at this time.