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.");
}
});
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Fiddle Pages
Your fiddles accessible under a custom domain and a vanity path - the simplest hosting for your personal project.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Get Fiddle Pages with PRO
Your fiddles accessible under a custom domain and a vanity path - the simplest hosting for your personal project.