From 9e403600a5baef5a16ccbb6c492c91649ffe62ad Mon Sep 17 00:00:00 2001 From: MohammadHoseinPaymard Date: Tue, 27 May 2025 11:05:16 +0330 Subject: [PATCH] update util.js --- util.js | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) 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