JSFiddle - React, Tailwind, and code Playground
HTML
<input type="text" name="qtdeQuestoes" id="qtdeQuestoes" size="3" maxlength="3" style="cursor: default;" value="200">
<input type="button" style="height: 30px; cursor: default;" id="geraAleatorio" value="Gerar">
<table id="tb-questoes-selecionadas" cellspacing="1">
<tbody>
<tr class="grid-table-title">
<td align="center" style="background-color: #e5e5e5;">Nome</td>
<td align="center" style="background-color: #e5e5e5;">Qtde</td>
</tr>
<tr class="trRemove">
<td class="td-center-center">RUBRA</td>
<td class="td-center-center">
<input type="text" maxlength="3" rel="146" name="D" id="146D" value="0" class="qtdeAssunto cadeadoaberto" style="width:30px;">
</td>
</tr>
<tr class="trRemove">
<td class="td-center-center">INDIGA</td>
<td class="td-center-center"> <input type="text" maxlength="3" rel="2824" name="A" id="2824A" value="0" class="qtdeAssunto cadeadoaberto" style="width:30px;"> </td>
</tr>
<tr class="trRemove">
<td class="td-center-center">FULVA</td>
<td class="td-center-center">
<input type="text" maxlength="3" rel="146" name="D" id="146D" value="0" class="qtdeAssunto cadeadoaberto" style="width:30px;">
</td>
</tr>
<tr class="trRemove">
<td class="td-center-center">INDUBRA</td>
<td class="td-center-center">
<input type="text" maxlength="3" rel="146" name="D" id="146D" value="0" class="qtdeAssunto cadeadoaberto" style="width:30px;">
</td>
</tr>
<tr class="trRemove">
<td class="td-center-center">BROLVA</td>
<td class="td-center-center">
<input type="text" maxlength="3" rel="146" name="D" id="146D" value="0" class="qtdeAssunto cadeadoaberto" style="width:30px;">
</td>
</tr>
...
JavaScript
var limiteQuestoes = 200;
$("#geraAleatorio").click(function(){
var colunasAbertas = $("#tb-questoes-selecionadas").find(".qtdeAssunto.cadeadoaberto");
var totalCampos = colunasAbertas.length;
var rand = new Array();
var randFinal = new Array();
var qtde = parseInt($("#qtdeQuestoes").val());
if(qtde <= limiteQuestoes){
var qtdeQuestoes = qtde;
}else{
alert("A quantidade máxima é " + limiteQuestoes + "!");
var qtdeQuestoes = limiteQuestoes;
$("#qtdeQuestoes").val(limiteQuestoes);
}
if(qtdeQuestoes >= totalCampos){
rand.push(0);
rand.push(parseInt(qtdeQuestoes));
// Gero números random de 0-Valor no input
while(rand.length <= totalCampos){
var valorGerado = 1 + Math.floor(Math.random() * qtdeQuestoes);
if(jQuery.inArray( valorGerado, rand ) == -1){
rand.push(valorGerado);
}
}
rand.sort(function(a,b){return a-b});
$.each(rand, function(index, value){
valor = rand[parseInt(index + 1)] - parseInt(value);
if(valor > 0){
randFinal.push(valor);
}
});
colunasAbertas.each(function(index, value){
$(value).val(randFinal[index]);
});
}else{
alert("O número de questões não pode ser menor que a quantidade de linhas.");
}
});