diff --git a/util.js b/util.js index 1fe07a3..3bd4206 100644 --- a/util.js +++ b/util.js @@ -530,6 +530,26 @@ function getRandomIp(){ return `${getRandomNumber(1, 254)}.${getRandomNumber(1, 254)}.${getRandomNumber(1, 254)}.${getRandomNumber(1, 254)}`; } +function getRandomNumber(min, max) { + return Math.floor(Math.random() * (max - min + 1)) + min; +} + +function areArraysEqualUnordered(arr1, arr2) { + if (arr1?.length !== arr2?.length) { + return false; + } + return arr1.every(item => arr2.includes(item)) && + arr2.every(item => arr1.includes(item)); +} + +function getRandomElement(arr) { + if (!Array.isArray(arr) || arr.length === 0) { + throw new Error("آرایه معتبر نیست"); + } + const randomIndex = Math.floor(Math.random() * arr.length); + return arr[randomIndex]; +} + module.exports = { sleep, convertStringToJson, @@ -548,5 +568,8 @@ module.exports = { realPayloadGenerator, hash, createUser, - getRandomIp + getRandomIp, + getRandomNumber, + areArraysEqualUnordered, + getRandomElement } \ No newline at end of file