mardi 25 juillet 2017

Generating non-repeating 6 numbers asking for maximum number in JS

Hi guys i have some code here asking for maximum number and generate 6 numbers .. but my problem is their a duplicate number generated, can someone tell me guys to correct my code...

<script>
function mygenerated()  { 
var rlts = document.getElementsByName("result");
for(var i=0 ; i<=5; i++)  { 
rlts[i].value=""; // clear results
}
var max=eval("document.lot.maxnum.value");
if (max.length<1) {
alert ("You must choose a number for the maximum value!");
document.lot.maxnum.focus();
return false;
}
for(var i=0 ; i<=5; i++)  { 
rlts[i].value=(Math.floor(Math.random()*max)+1);  
 }     
}
</script>

at first its look good but again there is a duplicate results appear.. :(




Aucun commentaire:

Enregistrer un commentaire