Have you ever wondered why mathematicians look at you strangely? Somewhere in the digits of pi, your diary is written in plain ASCII.
The basic mathematical operators were already described in section 6.10. Many additional mathematical functions are provided for various specialized purposes. These are described in the following sections.
 
Chance plays a large role in many types of games, so DM provides several
instructions that make use of randomness. In actual fact, they all rely on a
pseudo-random number generator which only appears to be random. However,
for all practical purposes, they can be relied upon to provide probabilistic
results with no discernible pattern.
 
 
The rand instruction generates a random number in the specified
range. The number returned is always an integer, so to get fractional
numbers, you would need to specify some larger range and then divide the
result.
 
 
If only a single argument is given, it is treated as the upper bound and the
lower bound takes its default of zero.
 
The following example makes a potion for gamblers.
 
 
Depending on how lucky the user is, the potion could do anything from -20 in
damage to +20 in healing.
 
This code assumes the definition of an  
 
The prob instruction is true or false with a probability specified
in the form of a percentage.
 
 
This can be used to choose between one of two possible outcomes. The
following example gives a player a certain chance of bad side-effects when
drinking a magic potion.
 
 
 
The roll instruction rolls some dice for you and returns the sum
obtained. The sides of the dice are numbered from one to the number of sides
and all are equally likely.
 
 
The dice parameters can either be specified as two separate numerical
arguments or as one combined text value. The text version might be useful
if you want to store the dice parameters in a single variable.
 
The following example uses roll to compute the impact of a weapon.
 
 
In both programming and combat, you have to make do with what you have.
 
 
The pick instruction randomly chooses one of its arguments and
returns that value.
 
 
If you want to give a particular value a higher or lower chance of being
chosen, a relative probability may be specified. A relative probability of
200 is twice as likely as the norm, 50 is half, and so on.
 
 
The following example uses pick() to implement a fortune cookie.
 
 
In this example, there are a couple messages with the normal default
probability, one a quarter as likely, and one a tenth as likely to be seen.
Note how prob() may be followed by a newline instead of a semicolon
since the two are equivalent. That allows you to line things up, if you are
the lining-up sort of person.
 
 
The abs instruction computes the absolute value of a number.
 
1. Randomness
1.1 rand
L is the lower bound. U is the upper bound. L and U.
obj/potion/lucky
 verb/drink()
 usr.AddLife(rand(-20,20))
AddLife() procedure that handles
healing or damaging a mob. It would be similar to the HurtMe() proc
defined in section 6.1 but with the meaning of the argument
reversed.
1.2 prob
P is the percent chance of being true.P percent of the time, otherwise 0.
obj/potion/health
 verb/drink()
 if(prob(20)) //backfire 20% of time
 usr.AddLife(-10)
 else
 usr.AddLife(20)
1.3 roll
dice is the number of dice to roll.sides is the number of sides on the dice.
obj/weapon
 var/power
 clipboard
 power = "1d4"
 calculator
 power = "2d6"
 verb/swing(mob/trg in view(1))
 var/damage = roll(power)
 view() << "[usr] hits [trg] with \a [src] for [damage] point\s!" 
1.4 pick
P is relative probability (default is 100). Val is the value with the altered likelihood.
obj/fortune_cookie
 verb/eat()
 usr << "The message inside says:" usr << pick ( "Never trust an undead doctor.", "Only trust undead lawyers.", prob(25) "The throne marks the way.", prob(10) "The wall behind the throne is an illusion!" ) del(src) 
2. abs
N is a numerical expression.