<script language="JavaScript" type="text/javascript">
  function randomGen(low,high, count){
   var myArray = new Array();
   if( high - low + 1  < count){
    alert("error with params!");
    return;
   }
   
   for( var i = 0; i < count; i++ ){
    var oneRand = randInt(low,high);
    var isContain = false;
    for( var j = 0; j < myArray.length; j++ ){
     if( myArray[j] == oneRand ){
      isContain = true;
      break;
     }
    }
    if( !isContain )
     myArray.push(oneRand);
    else
     i--;
   }
   
   return myArray;
  }
  
  function randInt(low,high) {
    return Math.floor(Math.random()*(high-low+1)+low);
  }
  
  // here is the test
  var testArray = randomGen( 3, 90, 80 );
  for( var k = 0 ; k < testArray.length; k ++){
   document.write(testArray[k] + "<br />");
  }
  
 </script>

相关文章:

  • 2021-10-22
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-01-16
  • 2021-10-18
  • 2021-12-18
  • 2022-01-28
相关资源
相似解决方案