0

generate random number between (for example) 10 and 100

give me the simplest code for this solution.. thank you

10th May 2017, 12:00 PM
boyd
boyd - avatar
4 Antworten
+ 10
function randVal(min,max){ return Math.floor(Math.random()*(max-min+1)+min); } alert(randVal(10,100));
10th May 2017, 12:04 PM
Burey
Burey - avatar
+ 4
var arr = []; for (var n = 1; n < 51; n++) arr.push(n); function randArrDel(a) { var i = Math.floor(a.length*Math.random()); return a.splice(i,1)[0]; } for (c = 0; c < 20; c++) console.log(randArrDel(arr));
10th May 2017, 12:49 PM
visph
visph - avatar
0
thnx its work... how about generate random number (from 1 to 50) without repeat the same number in (maybe) 20 row
10th May 2017, 12:39 PM
boyd
boyd - avatar
0
10th May 2017, 1:35 PM
Kirollos Ayman