Hi all, I am new to Postman and still trying to get my head around it
My case:
From request 1 I get in json response some values e.g. {“number”: 70}, {“number”: 2}, {“number”: -1},
In request 2 I am setting a random number in pre-request script like this: var randomFloorNo = pm.variables.set(“randomFloorNo”, _.random (-10,99));
and call the variable in request body like this:
{
“floorNumber”: {{randomFloorNo}},
}
My question:
I need to set the randomFloorNo in request 2 but excluding the values that I receive in request one.
e.g. set randomFloorNo any value between -10 and 99 but exclude the values 70, 2, -1
function generateRandom(min, max, exclude) {
let random;
while (!random) {
const x = Math.floor(Math.random() * (max - min + 1)) + min;
if (exclude.indexOf(x) === -1) random = x;
}
return random;
}
for (let i = 0; i < 25; i++) {
console.log(generateRandom(-10, 99, [2, -1]));
}