mardi 25 août 2020

How can I avoid generating the same number using a random number generator that I am assigning to two variables?

var randomDescriptor1 = descriptors[getRandomIndex(descriptors)];
  tagline1.innerText = randomDescriptor1;
  var randomDescriptor2 = descriptors[getRandomIndex(descriptors)];
  tagline2.innerText = randomDescriptor2;
function getRandomIndex(array) {
  return Math.floor(Math.random() * array.length);
}

I am altering an HTML file using dom and want to generate random descriptors in the same sentence. I pull from an array of stored strings, but sometimes they happen to return the same word twice in the sentence. How could I avoid this?




Aucun commentaire:

Enregistrer un commentaire