Throws two dice. Each with a different random value between 1 and 6. Use only first or both as required in your game!
Press any key or press the button to throw.
Another implementation is here with time delay between each die throw to make it more random in case generator has issues
|
Code snippet:
function dorand2(){
document.getElementById("chng").innerHTML = '';
var odice = document.getElementById("dice");
var r1 = getRandomInt(1, 6);
var r2 = getRandomInt(1, 6);
var r3 = getRandomInt(1, 6);
odice.innerHTML = "Dice A : " + r1 + " Dice B : " + r2 ;
}
/** http://stackoverflow.com/questions/1527803/generating-random-numbers-in-javascript-in-a-specific-range
* Returns a random integer between min (inclusive) and max (inclusive)
* Using Math.round() will give you a non-uniform distribution!
*/
function getRandomInt(min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
}
sel2in.com
(c) 2017 Tushar Kapila.