IBM BPM, V8.0.1, All platforms > Authoring services in Integration Designer > Developing monitor models > Create monitor models > Authoring XPath functions > Examples of XPath functions
Example of a random-number-generator function
Random number generator functions are one of several XPath 2.0 functions supported in model expressions in IBM Business Monitor. Define random number generator XPath functions for use in monitor model XPath expressions.
The following code exemplifies the use of the random number generator user-defined XPath function:
import static com.ibm.wbimonitor.xml.expression.udf.XPathType.Indicator.One; import java.math.BigDecimal; import java.math.BigInteger; import com.ibm.wbimonitor.xml.expression.udf.XPathFunction; import com.ibm.wbimonitor.xml.expression.udf.XPathType; public class Examples { public static final String NAMESPACE = "http://www.jimbo.org/beverages/functions"; @XPathFunction( namespaceName = NAMESPACE, localName = "random", //$NON-NLS-1$ description = "(max) Returns a random integer on the interval [0, max). If max is the empty sequence 0 will be returned.", isDeterministic = false, isSelfContained = true ) public static @XPathType(occurrenceIndicator = One) BigInteger randomNumber(final BigInteger max) { if (max == null) return BigInteger.ZERO; return new BigDecimal(max).multiply(new BigDecimal(Math.random())).toBigInteger();} }