Assigning x amount of random numbers to an array - Javascript Array Operation

Javascript examples for Array Operation:Array Element

Description

Assigning x amount of random numbers to an array

Demo Code

ResultView the demo in separate window

<html>
   <head></head>
   <body> 
      <script>
function getDistinctNumbers(count) {
var values = [];/* w ww  . j  a v a 2  s .  co m*/
for (var i=1; i<=64; i++)
  values.push(i);
values.sort(function(a,b){return Math.round(Math.random() * 2) -1;});
values.length = count;
return values;
}
console.log(getDistinctNumbers(24));
console.log(getDistinctNumbers(24));

      </script>  
   </body>
</html>

Related Tutorials