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.
Name | Return Type | Description |
---|---|---|
rand.double() | double | Returns a random double between 0 and 1 . |
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 . |
rand.double()
→ double
Returns a random double
between 0
and 1
.
- YAML
- JSON
# snippet
---
expressions:
- "rand.double() >= 0.5"
// 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:
- YAML
- JSON
# snippet
---
expressions:
- "rand.int() == 1"
// snippet
{
"expressions": [
"rand.int() == 1"
]
}
The following is an example of using rand.int
with custom values:
- YAML
- JSON
# snippet
---
expressions:
- "rand.int(0, 10) >= 5"
// snippet
{
"expressions": [
"rand.int(0, 10) >= 5"
]
}