How to use Random Numbers and other Math functions in VASSAL

USING RANDOM NUMBER & MATH FUNCTIONS IN VASSAL

If you use Beanshell expressions (the expressions displayed in { } or in the Expression field of a Calculated Property), then all of the Java math functions are available to you.

RANDOM NUMBERS:

((int)Math.floor(Math.random * 6) + 1) will return a random number between 1 and 6.

((int)Math.floor(Math.random * (max - min + 1)) + min) will return a number between "min" and "max".

MATH FUNCTIONS:

The most important Math "trick" to remember is that, for Vassal properties, you can't just pass in the property name directly, you have to use GetProperty.

So for example: Math.abs(GetProperty("MaybeNegative")) returns the absolute value of the property MaybeNegative.

Math.max(GetProperty("OneValue"), GetProperty("OtherValue")) returns the larger of OneValue and OtherValue.

Math.min(GetProperty("OneValue"), GetProperty("OtherValue")) returns the smaller of OneValue and OtherValue.

A complete list of the Math class methods can be found at e.g. Oracle Java Docs