CodeMirror: Dart mode

## Dart mode

import 'dart:math' show Random; void main() { print(Die(n: 12).roll()); } // Define a class. class Die { // Define a class variable. static final Random shaker = Random(); // Define instance variables. final int sides; int? lastRoll; // Define a constructor. Die({int n = 6}) : sides = n { if (4 > n || n > 20) { // Support for errors and exceptions. throw ArgumentError(/* */); } } // Define a method using shorthand syntax. @override String toString() => '$lastRoll'; // Define an instance method. int roll() { return lastRoll = shaker.nextInt(sides) + 1; } }