jeudi 19 novembre 2020

How to create an array containing non-repeating numbers? [duplicate]

this is my first question here.

I need to generate an array containing 16 random numbers and that's my solution:

  var arr = [];
      for (var i = 0; i < 16; i++) {
        arr.push(Math.floor(Math.random() * 100) + 1);
      }

The problem is that in this way it is possible that there are repeated numbers. Is there someone who can help me? Thanks in advance.




Aucun commentaire:

Enregistrer un commentaire