[backend][nodejs] Add seed to random decision

This commit is contained in:
koeberlue
2021-04-05 20:49:54 +02:00
parent 45b39fea22
commit 4a839343f5
3 changed files with 15 additions and 2 deletions

View File

@@ -1,4 +1,5 @@
const random = require('random');
const seedrandom = require("seedrandom");
class Choice {
constructor(name) {
@@ -16,7 +17,8 @@ const choices = [
new Choice('C')
];
exports.getRandomChoice = () => {
exports.getRandomChoice = (seed = new Date()) => {
random.use(seedrandom(seed));
return choices[random.int(0, choices.length - 1)];
}