Docs menu
Build a scenario
Scenario file Generators vars and const Time and pace Defaults Relationships Schedules Instances Lifecycle Collections Connections Delivery behaviorExpressions
Math
Money calculations should stay readable in JSON and repeat exactly in tests. Synthtraffic preserves decimal scale instead of exposing binary floating-point noise.
The result
{"unitPrice":19.99,"quantity":3,"subtotal":59.97,"discountLeft":9.95,"pricePerItem":19.99,"roundedScore":1.24}
Calculate an order
generators:
- name: orders
config:
maxEvents: 1
value:
unitPrice: 19.99
quantity: 3
subtotal: =multiply($unitPrice, $quantity)
discountLeft: =subtract(10.00, 0.05)
pricePerItem: =divide($subtotal, $quantity, round=2)
roundedScore: =round(1.236, 2)
Arithmetic functions
sum: =add(1, 2, 3)
difference: =subtract(10, 3)
product: =multiply(2, 3, 4)
ratio: =divide(10, 4)
power: =pow(2, 8)
rounded: =round(1.236, 2)
minimum: =min(3, 1, 2)
maximum: =max(3, 1, 2)
{"sum":6,"difference":7,"product":24,"ratio":2.5,"power":256,"rounded":1.24,"minimum":1,"maximum":3}
add(value, ...)andmultiply(value, ...)require at least two numbers.subtract(left, right),divide(left, right), andpow(base, exponent)take exactly two numbers.round(value, digits)requires a non-negative integer number of digits.min(value, ...)andmax(value, ...)accept one or more numbers. A single list is also accepted, which is useful for$items.price.
Division by literal zero fails validation. A divisor that evaluates to zero stops evaluation with a division-by-zero error.
Absolute value and whole numbers
abs(value, round?) returns the absolute value, preserving integer types and decimal scale. An explicit round=N sets the result scale. Fixed-point literals retain their written scale in abs, so abs(-3.70) emits 3.70; scaled values produced by other functions keep their scale too.
floor(value) rounds toward negative infinity; ceil(value) rounds toward positive infinity. Both return signed 64-bit integers and accept no modifiers. Integer inputs are processed without converting through floating point.
absolute: =abs(-3.70)
whole: =floor(3.70)
required: =ceil(3.10)
negativeFloor: =floor(-1.2)
negativeCeiling: =ceil(-1.2)
These emit 3.70, 3, 4, -2, and -1, respectively. Each function requires one finite numeric value: strings, booleans, null, collections, NaN, and infinities are errors. Signed minimum-integer absolute values and whole-number results outside the signed 64-bit range fail clearly. Invalid literals fail compilation; invalid evaluated arguments fail at runtime with source context. Structured block forms are not supported.
Decimal precision
Fractional literals carry their written scale into arithmetic. Values produced with round=N also keep that scale:
exact: =add(0.1, 0.2)
money: =multiply(19.99, 3)
average: =divide(10, 3, round=2)
{"exact":0.3,"money":59.97,"average":3.33}
round=N is available on arithmetic functions including abs, except floor, ceil, and the round wrapper itself. It is also available on sum and avg.
List aggregates—sum, count, and avg—are covered with nested data in Collections.