mardi 14 avril 2020

Random but equal probability fetch requests to array of URL JavaScript [duplicate]

I have an array of URLs, and I would like fetch requests to be evenly distributed among them.

Is this the right approach?

// randomly get one URL with equal probability
var idx = Math.floor(Math.random() * ArrURLs.length);

var randomResponse = await fetch(ArrURLs[idx]);



Aucun commentaire:

Enregistrer un commentaire