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:

IMPORTANT: Vassal properties must be defined as numerical so that Java sees them as such!!!

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

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

Math.min(OneValue, 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