synthtraffic Get started
Docs menu

Expressions

Selection

Use a selection function when a field should come from a controlled set rather than an unrestricted random generator.

The result

cycle makes the status progression predictable. The one-choice examples make the other return shapes visible:

{"status":"CREATED","channel":"store","featuredProduct":"keyboard"}
{"status":"PAID","channel":"store","featuredProduct":"keyboard"}
{"status":"DELIVERED","channel":"store","featuredProduct":"keyboard"}

Select order values

YAML order-selections.yaml
defaults:
  seed: 42
generators:
  - name: orders
    config:
      maxEvents: 3
    value:
      status: =cycle(CREATED, PAID, DELIVERED)
      channel: =categorical(store=1)
      featuredProduct: =oneOf(keyboard)

oneOf(value, ...)

Picks one positional value with equal probability. At least one value is required.

status: =oneOf(CREATED, PAID, CANCELLED)
product: =oneOf(keyboard, mouse, monitor)
{"status":"CREATED","product":"monitor"}
{"status":"PAID","product":"keyboard"}
{"status":"CREATED","product":"mouse"}

oneOf supports nullable, optional, cardinality, and unique.

cycle(value, ...)

Returns values in order and starts over after the final value. Its position is scoped to the evaluated field path and is preserved while that generator evaluator is active.

status: =cycle(CREATED, PROCESSING, COMPLETED)
region: =cycle(us-east, us-west, eu-central)
{"status":"CREATED","region":"us-east"}
{"status":"PROCESSING","region":"us-west"}
{"status":"COMPLETED","region":"eu-central"}

cycle is deterministic and does not accept random-value modifiers.

categorical(name=weight, ...)

Picks a named choice by relative weight.

source: =categorical(web=0.7, mobile=0.2, store=0.1)
{"source":"store"}
{"source":"web"}
{"source":"web"}

Block form is also supported:

source:
  =categorical:
    web: 0.7
    mobile: 0.2
    store: 0.1
{"source":"store"}
{"source":"web"}
{"source":"web"}

Every weight must be a positive numeric literal. Weights are relative and do not need to sum to 1; web=7, mobile=2, store=1 has the same proportions as the example above.

Compact choices must use named weights. Use block form when choices are easier to scan vertically.

Lifecycle transitions can also use block-form categorical; see Lifecycle.

Next: control nulls, omissions, precision, and value pools.