lundi 30 septembre 2019

How do I generate random numbers with a certain interval?

I have this sample:

link

CODE JS:

for (var i=0; i < 5; i++) {
  var number = 1 + Math.floor(Math.random() * 20);
  console.log(number);
}

I want to generate numbers between 1 and 20 but with the following restrictions:

  1. The numbers should not be duplicated
  2. Exclude the first and last numbet (1,20)
  3. The difference between the generated numbers must be at least 3 (ex: 4, 7,10 etc)

Can you please give me some tips on how I could do this?

A few simple examples would help me.

Thanks




Aucun commentaire:

Enregistrer un commentaire