samedi 29 avril 2017

how to make generate random numbers that don't repeat

var randomArray = [];

function random(x) {
    var emptyRandom = null;
    temp = Math.floor(Math.random() * x);
     emptyRandom = temp;
     return emptyRandom;

}

for (var i = 10; i > 0 ; i--) {
    randomArray.push(random(10));
}
console.log(randomArray);
<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title>practice</title>

    </head>
    <body>


    <script src="script.js" charset="utf-8"></script>
    </body>
</html>

i want to shuffle the randomArray to make sure numbers don't repeat, All the answers that people post are very hard to understand for a beginner so if you can please explain how you do it that would help me a lot!




Aucun commentaire:

Enregistrer un commentaire