javascript - How to generate non-equal random numbers -
i trying find 10 random numbers between 100 , 1000 , if of numbers equal need have computer take different random number. know how this?
<script type="text/javascript"> var numbers=[]; var max=110; var min=100; numbers [1]= math.floor(math.random() * (max - min + 1)) + min; numbers [2]= math.floor(math.random() * (max - min + 1)) + min; numbers [3]= math.floor(math.random() * (max - min + 1)) + min; numbers [4]= math.floor(math.random() * (max - min + 1)) + min; numbers [5]= math.floor(math.random() * (max - min + 1)) + min; numbers [6]= math.floor(math.random() * (max - min + 1)) + min; numbers [7]= math.floor(math.random() * (max - min + 1)) + min; numbers [8]= math.floor(math.random() * (max - min + 1)) + min; numbers [9]= math.floor(math.random() * (max - min + 1)) + min; numbers [10]= math.floor(math.random() * (max - min + 1)) + min; (numbers[2]); while (numbers[1]===numbers[2]); (numbers[3]); while (numbers[1] == numbers[3]) (numbers[2] == numbers[3]); (i in numbers){ document.writeln("<br>"+numbers[i]); } </script>
you utilize like
<script> var foo = {} while (object.keys(foo).length < 10) { foo[math.floor(math.random() * (max - min + 1)) + min] = true; } var numbers = object.keys(foo); </script>
javascript arrays random
No comments:
Post a Comment