var times = 3600; var res = test(times, 3); console.log(res); function test(num, aNum){ var a = num / aNum; var r = []; var numLen = (num.toString()).length; var flag = '1'; if( numLen > 2) { for( var i=0;i<(numLen - 2);i++) { flag += '0'; } } for(var i=0;i<aNum;i++){ var random = Math.floor(Math.random()*9); var tt = (random * aNum) * parseInt(flag) console.log( 'tt',tt ); r[i] = a; } return r; }