You can do as follows below using this function randomNumber
javascript:
function randomNumber(min, max) {
return Math.floor(((max + 1) - min) * Math.random() + min);
}
alert(randomNumber(85659, 85325));
Solution based on your Javascript HTML:
function randomNumber(min, max) {
return Math.floor( ((max + 1) - min) * Math.random() + min);
}
function gerarNumeros() {
var txtInicial = document.getElementById('inicial'),
txtFinal = document.getElementById('final'),
result = document.getElementById('result');
var numeroInicial = parseInt(txtInicial.value),
numeroFinal = parseInt(txtFinal.value);
var count = 0;
var intervalo = setInterval(function() {
//Gerando 20 números por vez.
for (var i = 0; i < 20/*20000*/; i++) {
var numeroGerado = randomNumber(numeroInicial, numeroFinal);
result.innerHTML = result.innerHTML + '<p>' + count + ' : ' + numeroGerado + '</p>';
count++;
}
if (count === 20000) {//Quando o total de números gerados for 20000, parar de gerar.
clearInterval(intervalo);
}
}, 1000);//Gerar em 1 e 1 segundo.
}
p {
padding: 2px;
margin: 2px;
}
<form class="form-inline">
<div class="form-group">
<label for="inicial">Inicial</label>
<input type="number" class="form-control" id="inicial" placeholder="Número Inicial">
</div>
<div class="form-group">
<label for="final">Final</label>
<input type="number" class="form-control" id="final" placeholder="Número Final">
</div>
<button type="button" class="btn btn-default" onclick="gerarNumeros()">Iniciar</button>
</form>
<div id="result"></div>
Solution based on your HTML in PHP:
<?php
$numeroInicial = 85325;//$_GET['inicial'];
$numeroFinal = 85659;//$_GET['final'];
echo '<h1>Resultado:</h1>';
for ($i = 0; $i < 20000; $i++) {
echo '<p>' . $i . ' : ' . mt_rand($numeroInicial, $numeroFinal) . '</p>';
}
Post what you tried to do, which helps. About being PHP or JS, it just depends on the purpose. If it is something that cannot be changed by the user, better on the PHP side.
– Bacco