# How to use Random Numbers and other Math functions in VASSAL

**URL:** <https://forum.vassalengine.org/t/how-to-use-random-numbers-and-other-math-functions-in-vassal/79294>\
**Category:** Documentation\
**Created:** [March 29, 2024, 10:52pm UTC](https://forum.vassalengine.org/t/how-to-use-random-numbers-and-other-math-functions-in-vassal/79294 "2024-03-29T22:52:48Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![slimy](https://forum.vassalengine.org/user_avatar/forum.vassalengine.org/slimy/32/4448_2.png) [@slimy](https://forum.vassalengine.org/u/slimy)\
**Post date:** [March 29, 2024, 10:52pm UTC](https://forum.vassalengine.org/t/how-to-use-random-numbers-and-other-math-functions-in-vassal/79294/1 "2024-03-29T22:52:49Z")

</div>

**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:**

**Random(6)** will return a random number between 1 and 6.

**Random(min, max)** will return a number between “min” and “max”.

**IsRandom()** will return true 50% of the time.

**IsRandom(pct)** will return trure pct% of the time.

**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](https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/lang/Math.html) and the useful ones are included in the Beanshell Expression Builder.
