javascript - unique random number generator problem -


i trying make random number generator. problem is, begins 0 begin 1

var found=false var current = new array() var maxvalue=4  var numunique=3   var count=0 var current = new array(numunique) getunique()  alert("the unique numbers are: " + current[0] + ", " + current[1] + ", , " + current[2])   function getunique()   {     (i=0;count<numunique;count++)     {       found=false       var rndvalue = get_random()       var j=0       (j=0;j<current.length;j++)       {         if (current[j] == rndvalue)         {           found=true           break         }       }       if (found)       {         count--       } else {         current[count]=rndvalue       }     }   }   function get_random()   {     var rannum= math.round(math.random()*maxvalue);     return rannum;   } 

thanks, regards

you have value 0-maxvalue, , want 1 maxvalue? i'd suggest this

var rannum= math.round(math.random()*(maxvalue-1))+1; 

Comments