Created
February 17, 2021 21:15
-
-
Save vincentlg/492276032f1320e5cc1da28de798a03f to your computer and use it in GitHub Desktop.
Script used for revealing mystery cards from a block hash
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const RNG = require('rng-js'); | |
const COMMON = 21; | |
const UNCOMMON = 22; | |
const RARE = 23; | |
const MYTHIC = 24; | |
function shuffle(array, rng) { | |
let m = array.length, t, i; | |
// While there remain elements to shuffle… | |
while (m) { | |
// Pick a remaining element… | |
i = Math.floor(rng.uniform() * m--); | |
// And swap it with the current element. | |
t = array[m]; | |
array[m] = array[i]; | |
array[i] = t; | |
} | |
return array; | |
} | |
function generate(blockHash) { | |
const all = [ | |
...Array(777).fill(COMMON), | |
...Array(72).fill(UNCOMMON), | |
...Array(36).fill(RARE), | |
...Array(3).fill(MYTHIC), | |
]; | |
const rng = new RNG(blockHash); | |
return shuffle(all, rng); | |
} | |
async function main() { | |
const blockHash = process.env.BLOCK_HASH; | |
if (!blockHash) { | |
console.log('BLOCK_HASH required'); | |
process.exit(1); | |
} | |
const models = generate(blockHash); | |
console.log(JSON.stringify(models)); | |
} | |
module.exports = (callback) => main().then(() => callback()).catch(callback); | |
main(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment