function getLucky(serverSeed, clientSeed, nonce) { var hash = hmac_sha512(client_seed + ":" +nonce, server_seed); var index = 0; do { var lucky = parseInt(hash.substr(index, 5), 16); index += 5; } while (lucky >= 1e6); return lucky; }