mardi 27 août 2019

Making a BINGO game. How do I generate a random number to be displayed from one set without repeating which number is generated and displayed?

I'm making a bingo game for a course I'm taking, and the assignment is to generate a random pick/element from a pre-setup Set();, display that random value (it's going to be a letter and number e.g. G78, so not an integer), and then make sure that the number is not called again until the game is reset

So far, I'm able to generate a random number and have it displayed, but I can't figure out how to keep the generator from repeating which element from the set it picks to display

let numbers = new Set();
.add("O65")
            .add("O66")
            .add("O67")
            .add("O68")
            .add("O69")
            .add("O70")
            .add("O71")
            .add("O72")
            .add("O73")
            .add("O74")
            .add("O75");

 let guess = Array.from(numbers);

 let checks = new Array();

 function getRandomNumber()
            {
                function rando()
                {
                    for(let g = guess; g = guess.length; g++)
                    {
                        let rand = guess[Math.floor(Math.random() * 
guess.length)];
                        return rand;
                    }


                }
                let num = rando();
                document.getElementById('bingo').innerHTML = num;
                checks.push(num);
                /*if(numbers.has(num))
                {
                    numbers.delete(num);
                }*/
            }

Here, I'm able to generate a random value to be displayed, but sometimes I get one that's already been called. I don't want that to happen, each value from the set should only be generated and displayed once until the program is reset or the entire set has been called




Aucun commentaire:

Enregistrer un commentaire