Get better conclusions from a javascript randomizer I have a simple javascript randomizer that compares two random numbers with values 1 to 6.

I want to get a good estimate about the probability of the first been greater than the second. I could do it using math, probability theory e.t.c. but lets say that I want to stick to javascript. Using millions or billions of itterations gives better estimates but I can't push that too far (especially since codepen, jsFiddle e.t.c. don't allow that many). Am I missing something? Is there a better way to estimate this probability? Right now, I just run the program (with 1000 itterations) a couple of times and calculate the average value but that gives values in quite a wide range, I'd like to get more restricted results.



var xIsGreater = 0;
var yIsGreater = 0;
for(j=0;j&lt;1000;j++){
  var x = Math.floor(Math.random() * 6) + 1  ;
  var y = Math.floor(Math.random() * 6) + 1  ;
  if(x&gt;y){
    xIsGreater++;
  }else if(y&gt;x){
    yIsGreater++;
  }
}
var draw = 1000-xIsGreater-yIsGreater;
console.log(xIsGreater+'--'+yIsGreater+'--'+draw);
Math.random() should be adequate for most pseudo-random use cases that don't need to be cryptographically secure.

You can consider using RandomSource.getRandomValues() (MDN Documentation) for a a more random distribution, but this may also come at the cost of more resources being utilized in generating the random number.

You may also have cross-browser compatibility issues as this is newer javascript API.