1
Beauty guys? It happens the following, I created a tool to generate gambling (quina, mega sena and etc. link tool: generaterandom.000webhostapp.com)
In the attached image we see the part where the algorithm puts 60 random numbers in an array Then it is traversed the entire array to check if a number left repeated, if it was repeated, all 60 numbers are generated again, this is making it very heavy and this recursion is getting in the way of a lot, crashing and returning me "Uncaught Referenceerror: Function is not defined"
I wanted to know if it is possible to optimize this part of the code, with only one for, generate 1 number, see if it is in the array and add, would be fewer lines, less for and I believe that would not lock, but I can not do this optimization in the lines, I did but it didn’t work out... can someone guide me? whole fuction link: generaterandom.000webhostapp.com/gerarJogos.js
for (var i = 0; i < comprimento; i++){
vet[i] = Math.floor(Math.random() * 60 + 1);
}
for (var z = 0; z < comprimento; z++){
for(var y = 0; y < comprimento; y++){
if(z !== y){
if(vet[z] === vet[y]){
gerarJogos();
}
}
}
About posting code as image, please read Manual on how NOT to ask questions
– Woss