vendredi 3 novembre 2017

How to draw lots figures always different like in the lottery?

I would like to ask about one tiny riddle. I want to draw lots within in this example 15 figures that should always be different like in the lottery. I have already checked first condition. If for example 1 is equal 1 - please draw lots again, but there is possibility that next sorting will show again number 1. I would like to avoid this some way, to exclude it. There cannot be drawn lots figures the same. Some ideas? :-)

var figureShowed = document.querySelector("div");
        var button = document.getElementById("random-figure");
        var allFigures = [];

        button.addEventListener("click", drawAmount);

        function drawAmount() {

            for (i = 0; i <= 5; i++) {
                var random = Math.floor(Math.random() * 15 + 1);

                if (allFigures[0] === allFigures[1, 2, 3, 4, 5]) {
                    allFigures[0] = random;
                } else {
                    allFigures[i] = random;
                }
            }
            figureShowed.textContent = allFigures.join(" | ");
        }




Aucun commentaire:

Enregistrer un commentaire