Generate 4-digit algebraic numbers [0000-9999] [duplicate]

-2

Here's the example below of what's happening, I stated 1198805- and the remainder is generated. But with that defect below.

1198805522
11988052636
11988054970
1198805929
11988054269
11988054150
1198805671
1198805848
11988055359

Follow the Javascript Code used:

var maximo = 8999;
var resultados = 40;
var stop;
var contador = 0;
	//var txt = document.getElementById("txtsenha").value;
    var txt = "11" + "" + "9" + "9204" + "-";
   // document.getElementById(el).innerHTML += txt + x + "<br>";
	document.getElementById('contadorrr').innerHTML = '<font color=#FFF size="6"> <b>-</b>Loanding<b>-</b> </font><font size="29">[</font><font size="59" color=#1E90FF> ' + contador + '</font><font size="29">]</font><font size="29" color=#1E90FF>' ;

var i, arr = [];
for (i = 0; i < maximo; i++) {
    arr[i] = i + 1;
}

var p, n, tmp;
for (p = arr.length; p;) {
    n = Math.random() * p-- | 0;
    tmp = arr[n];
    arr[n] = arr[p];
    arr[p] = tmp;
	}

for (var i = 0; i < resultados; i++) {
 document.getElementById('out').innerHTML += txt + arr[i]+ '<br> ';
}
			</head>
<body style="background-image:url(https://i.ytimg.com/vi/gJ16uN47EAk/maxresdefault.jpg);">
<hr>
        <div class="configdiv" align="center"  style="color: #F8F8FF;">
<p><font size="15">-</font> <font size="7" color="#B5B5B5">SPACE GHOST V1.0</font> <font size="15">-</font></p> 

                <img align="center" src="http://img15.deviantart.net/49f9/i/2015/167/5/2/space_ghost_logo_by_topher147-d8x52wm.png"width="300" height="250" >
				
				
<div id="contadorrr"><font size="20" color="#FFD700"><strong></strong></font></div>
<br><br><HR>


<hr>

<font size="20" color="#20B2AA">[</font> <font size="20" color="#D3D3D3"><strong> NUMEROS </strong></font> <font size="20" color="#20B2AA">]</font>
<div id="out" align="center"  style="color: #00BFFF;"></div>
<hr></hr>
<div id="interval" align="center" style="color: #00FF00;"></div>

The 4 digits drawn, total the total of 5040 different combinations without repetition But in my code it generates broken lines of 10, sometimes 12-digit, and this interferes with the total of REAL results (11 digits)

Does anyone know how to limit code to generating only 11 digits?

Thank you.

    
asked by anonymous 22.04.2017 / 01:26

1 answer

4

function pad(str, length) {
  const resto = length - String(str).length;
  return '0'.repeat(resto > 0 ? resto : '0') + str;
}

var resultados =5040;
var maximo = 9999;
var arr = [];
while(arr.length < resultados){
    var random = Math.floor(Math.random() * maximo)
    random = pad(random, 4);
    if(arr.indexOf(random) > -1) continue;
    arr[arr.length] = random;
    console.log("11" + "" + "9" + "8805" + random);
}
    
22.04.2017 / 01:53