jeffdeon

Random Dice Algorithm

Sep 27th, 2020
930
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

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×