Randomize query params

Hi!

Im trying to randomize params for a query request by using pre-request Script. At the moment i have:

let queryParams = '';

const nft = {
    owneraddress: "0x434235346353f010C052440C1486",
};
queryParams = '?' + Object.keys(nft).map(key => `${key}=${nft[key]}`).join('&');
pm.globals.set("queryParams", queryParams);

const nft1 = {
    active: "true",
};
queryParams = '?' + Object.keys(nft1).map(key => `${key}=${nft1[key]}`).join('&');
pm.globals.set("queryParams", queryParams);

Is there a was to randomize what params to add to the query request? Lets say that i run it now, so the nft params are added, then if i run it again the nft1 is added, or even combine both params.

Sounds like a tricky one, and i dont even know if it possible.

Any ideias?

So i think i figured out a solution.

Here it is, might help someone:

let queryParams = '';

const nft = {
    owneraddress: "0x486AB254e9574534B3d298C4FC3f0234234230C1486",
    name: "nftMint",
    active: "true",
    servicename: "trybegame",
};

let headers = {};

const numberOfArguments = Math.floor(Math.random() * Object.keys(nft).length - 1) + 2;

var nftKeysList = Object.keys(nft);
var randomKeys = [];
do {
  randomKeys[randomKeys.length] = nftKeysList.splice(Math.floor(Math.random() * nftKeysList.length), 1)[0];
} while (randomKeys.length < numberOfArguments + 1);

for (let i = 0; i < randomKeys.length - 1; i ++) {
  headers[randomKeys[i]] = nft[randomKeys[i]]
}
console.log(numberOfArguments);

queryParams = '?' + Object.keys(headers).map(key => `${key}=${headers[key]}`).join('&');
pm.globals.set("queryParams", queryParams);