const crypto = require('crypto'); // You need to set these values const clientSeed = 'a6fc4f96bbe5fd17772f29a557b53b3439decc1496f3ac00dc76456f4bb9febf'; const serverSeed = '322e5766d56ca1ab33daca1b88e2620356039118313dee6a466f2667447d56ce'; var nonce = 1875499; const nonceLimit = 1879121; // Here we use the seeds to calculate the spin (a number ranging from 0 to 14) var rolls = ""; while (nonce <= nonceLimit) { const roll = getRollSpin(serverSeed, clientSeed, nonce); const rollColour = getRollColour(roll); rolls += " " + rollColour; nonce ++; } console.log(rolls); /* Below this line are algorithmic functions which we use to calculate the Spin ================================================================================== ================================================================================== */ function getRollSpinFromHash(hash) { const subHash = hash.substr(0, 8); const spinNumber = parseInt(subHash, 16); return Math.abs(spinNumber) % 15; } function getRollSpin(serverSeed, clientSeed, nonce) { const seed = getCombinedSeed(serverSeed, clientSeed, nonce); const hash = crypto.createHmac('sha256', seed).digest('hex'); return getRollSpinFromHash(hash); } function getCombinedSeed(serverSeed, clientSeed, nonce) { return [serverSeed, clientSeed, nonce].join('-'); } function getRollColour(roll) { if(roll === 0) { return 'green'; } if(roll <= 7 && roll >= 1) { return 'red'; } return 'black'; }
Write, Run & Share NodeJS code online using OneCompiler's NodeJS online compiler for free. It's one of the robust, feature-rich online compilers for NodeJS language,running on the latest LTS version NodeJS 16.14.2. Getting started with the OneCompiler's NodeJS editor is easy and fast. The editor shows sample boilerplate code when you choose language as NodeJS and start coding. You can provide the dependencies in package.json
.
Node.js is a free and open-source server environment. Node.js is very popular in recent times and a large number of companies like Microsoft, Paypal, Uber, Yahoo, General Electric and many others are using Node.js.
Google chrome's javascript engine V8
and is pretty fast.Asynchronous
, event-driven
and works on single-thread model
thus eliminating the dis-advantages of multi-thread model.Express is one of the most popular web application framework in the NodeJS echosystem.
let moment = require('moment');
console.log(moment().format('MMMM Do YYYY, h:mm:ss a'));
const _ = require("lodash");
let colors = ['blue', 'green', 'yellow', 'red'];
let firstElement = _.first(colors);
let lastElement = _.last(colors);
console.log(`First element: ${firstElement}`);
console.log(`Last element: ${lastElement}`);
Following are the libraries supported by OneCompiler's NodeJS compiler.