Skip to main content

Utility Macros

ngrok also exposes a number of utility macros in the Traffic Policy engine that are available in addition to the core macros. These macros should be generally available on all phases unless marked otherwise.

NameReturn TypeDescription
rand.double()doubleReturns a random double between 0 and 1.
rand.int(min int, max int)intReturns a random int between the provided min and max values. Only supports positive integers and min must be larger than the provided max. By default, min is 0 and max is 1.

rand.double()double

Returns a random double between 0 and 1.

# snippet
---
expressions:
- "rand.double() >= 0.5"

rand.int(min int, max int)int

Returns a random int between the provided min and max values. Only supports positive integers and min must be larger than the provided max. By default, min is 0 and max is 1.

The following is an example of using rand.int with the default values:

# snippet
---
expressions:
- "rand.int() == 1"

The following is an example of using rand.int with custom values:

# snippet
---
expressions:
- "rand.int(0, 10) >= 5"