roll

Parse a dice notation string and roll it

float
roll
(
string input
)

Parameters

input
Type: string

String of dice notation

Return Value

Type: float

The result of the roll as a float

Examples

1 auto rolled = roll("3d6k2+1d20");
2 assert(rolled < 33);
3 assert(rolled > 2);
4 
5 rolled = roll("1d20+8-3*2");
6 assert(rolled < 23);
7 assert(rolled > 2);
8 
9 rolled = roll("1d20d2");
10 assert(rolled == 0);
11 
12 rolled = roll("2d20k1");
13 assert(rolled < 21);
14 assert(rolled > 0);
15 
16 rolled = roll("3d10kl2");
17 assert(rolled < 21);
18 assert(rolled > 1);
19 
20 rolled = roll("10d20dh5");
21 assert(rolled < 101);
22 assert(rolled > 4);
23 
24 rolled = roll("ceil(1d6/2)");
25 assert(rolled > 0);
26 assert(rolled < 4);
27 
28 rolled = roll("floor(1d6/2)");
29 assert(rolled > -1);
30 assert(rolled < 4);
31 
32 rolled = roll("round(1d6/2)");
33 assert(rolled > 0);
34 assert(rolled < 4);
35 
36 rolled = roll("abs(1d6-100)");
37 assert(rolled > 0);
38 assert(rolled < 100);
39 
40 rolled = roll("(2000-1999)d20");
41 assert(rolled > 0);
42 assert(rolled < 21);
43 
44 rolled = roll("10d2!");
45 assert(rolled > 9);
46 
47 rolled = roll("10x20");
48 assert(rolled == 200);
49 
50 rolled = roll("{3d6,3d6,3d6,3d6}k1");
51 assert(rolled > 2);
52 assert(rolled < 19);
53 
54 rolled = roll("4dF");
55 assert(rolled > -5);
56 assert(rolled < 5);
57 
58 rolled = roll("3d6>3f>5");
59 assert(rolled > -1);
60 assert(rolled < 4);
61 
62 rolled = roll("3d6=4");
63 assert(rolled > -1);
64 assert(rolled < 4);

Meta