refactor: replace math.random with crypto

This commit is contained in:
Barış Soner Uşaklı
2024-12-09 18:18:02 -05:00
parent c69765e305
commit 9d2af7e10c
8 changed files with 39 additions and 8 deletions

View File

@@ -3,6 +3,7 @@
module.exports = function (module) {
const _ = require('lodash');
const helpers = require('./helpers');
const { secureRandom } = require('../../utils');
module.setAdd = async function (key, value) {
if (!Array.isArray(value)) {
@@ -200,7 +201,7 @@ module.exports = function (module) {
return;
}
const randomIndex = Math.floor(Math.random() * data.members.length);
const randomIndex = secureRandom(0, data.members.length - 1);
const value = data.members[randomIndex];
await module.setRemove(data._key, value);
return value;