Skip to content

Instantly share code, notes, and snippets.

@sofish
Created January 27, 2021 02:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sofish/a2ebd14e4aeff5d61805f82068d4f2e2 to your computer and use it in GitHub Desktop.
Save sofish/a2ebd14e4aeff5d61805f82068d4f2e2 to your computer and use it in GitHub Desktop.
random.js
$ node test.js
const os = require('os');
module.exports = function random() {
return +(process.hrtime()[1] * os.freemem() % 1000 / 1000).toFixed(2);
}
const rand = require('./random');
const map = {};
const mapLang = {};
for (let i =0; i < 2000; i++) {
incr(Math.floor(rand() * 10), map);
incr(Math.floor(Math.random() * 10), mapLang);
}
console.log(JSON.stringify(map, null, 2));
console.log(JSON.stringify(mapLang, null, 2));
function incr(k, data) {
if(data[k]) {
data[k] += 1;
} else {
data[k] = 1;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment