Simulated Dice Throw Tutorial

Published :
Author :
Adam Khoury
Learn to simulate dice throws for any type of numbered dice. You can roll the regular six sided dice or roll a 16 sided die for Dungeons and Dragons type games. We use a simple 1 - 6 random number generation technique to pinpoint two six sided dice in this tutorial since that is the most common type of dice used in online gambling and gaming. roll_btn.addEventListener(MouseEvent.CLICK, rollDice); function rollDice(event:MouseEvent):void{ var die1:uint = Math.floor(Math.random() * 6) + 1; var die2:uint = Math.floor(Math.random() * 6) + 1; var diceTotal:uint = die1 + die2; die1_txt.text = die1.toString(); die2_txt.text = die2.toString(); status_txt.text = "You rolled "+diceTotal; if(die1 == die2){ doubles_txt.text = "DOUBLES! You get a free turn"; } else { doubles_txt.text = ""; } }