jeffdeon

Random Dice Algorithm

Sep 27th, 2020
379
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. export abstract class DiceController {
  2.     abstract throwDice(): IDicePair
  3. }
  4.  
  5. export class RandomDiceController extends DiceController {
  6.  
  7.     throwDice(): IDicePair {
  8.         return this.throwRandomDice()
  9.     }
  10.  
  11.     private throwRandomDice(): IDicePair {
  12.         const dicePair = {
  13.             dice1: randomNumberBetween(1, 6),
  14.             dice2: randomNumberBetween(1, 6),
  15.         }
  16.         return dicePair
  17.     }
  18. }
  19.  
  20. /// Includes the values given
  21. export function randomNumberBetween(minValue: number, maxValue: number): number {
  22.     return Math.floor(Math.random() * (maxValue - minValue + 1)) + minValue
  23. }
RAW Paste Data