Skip to main content

How to Generate a Random Number Within a Given Range

You

can use the following JavaScript expression to generate a random integer within a specified range, including both the minimum and maximum values:

var $randomnumber = Math.floor(Math.random() * ($maximum - $minimum + 1)) + $minimum;

For example, the following code generates a random integer between 3 and 7:

An example below:

var $randomnumber = Math.floor(Math.random() * (7 - 3 + 1)) + 3;

The generated value can be 3, 4, 5, 6, or 7.

The random value can then be used in a Test Designer action. For example:

_highlight(_link($randomnumber, _near(_span("Smart Account"))))

This approach is useful when test scripts need to select or interact with different values dynamically during execution.


Last updated: MarchAugust 09,21, 20232026

If you have any feedback on this topic, please contact us at documentation@appvance.ai