Skip to content

Instantly share code, notes, and snippets.

@paulohenriquesn
Created April 13, 2021 06:31
Show Gist options
  • Save paulohenriquesn/cb5af4ebaac209b074e99dd310c55f2f to your computer and use it in GitHub Desktop.
Save paulohenriquesn/cb5af4ebaac209b074e99dd310c55f2f to your computer and use it in GitHub Desktop.
(async () => {
const si = require('systeminformation');
const cron = require('node-cron')
let counter = 0;
let Seed = `${new Date().getSeconds()}${new Date().getDate()}`;
const addSeed = (args) => {
for (let i = 0; i < args.length; i++) {
Seed += args[i];
}
}
const generateSeed = () => {
counter++;
if (Seed.length < 15) {
addSeed([new Date().getSeconds() * counter, new Date().getDate() * counter])
} else {
Seed = `${Seed.substr(5, 8)}${Seed.substr(0, 8)}${counter * 2}`
}
}
cron.schedule("*/1 * * * * *", async () => {
generateSeed()
})
let cpu_data = await si.cpu()
addSeed([cpu_data.cores, cpu_data.physicalCores, parseInt(cpu_data.family), parseInt(cpu_data.model)]);
const randomInt = (min, max) => {
let seed = parseFloat(`0.${(parseFloat(Seed)).toString().substr(0, 18)}`);
min = Math.ceil(min);
max = Math.floor(max);
return Math.floor(seed * (max - min)) + min;
}
console.log(`Numero aleatorio de 1 até 10: ${randomInt(0, 10)}`)
console.log(`Numero aleatorio de 10 até 20: ${randomInt(10, 20)}`)
console.log(`Numero aleatorio de 100 até 1000: ${randomInt(100, 1000)}`)
console.log(`Numero aleatorio de 1000 até 2000: ${randomInt(1000, 2000)}`)
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment