i got an array [1,2,3,4,5,6,7,8,9] from this array i want to take out two random values, later these 2 values adds to each other. But the random values cant be the same (5+5=10 equals a wrong equation) and also if the first random number occured in the first execution of the code its not supposed to occur the second time. How would i go about to code this?
so far ive tried something like this
list = [1, 2, 3, 4, 5, 6, 7, 8, 9];
function makeRandom() {
random1 = list.splice(Math.floor(Math.random() *
list.length), 1);
random2 = list.splice(Math.floor(Math.random() *
list.length), 1);
console.log(list);
console.log(random1);
console.log(random2);
}
makeRandom()
Aucun commentaire:
Enregistrer un commentaire