Files
decision-maker/backend/nodejs/random-decision.js
2021-04-05 20:49:54 +02:00

25 lines
454 B
JavaScript

const random = require('random');
const seedrandom = require("seedrandom");
class Choice {
constructor(name) {
this.name = name;
}
toString() {
return this.name;
}
}
const choices = [
new Choice('A'),
new Choice('B'),
new Choice('C')
];
exports.getRandomChoice = (seed = new Date()) => {
random.use(seedrandom(seed));
return choices[random.int(0, choices.length - 1)];
}
exports.choices = choices;