Docs menu
Build a scenario
Scenario file Generators vars and const Time and pace Defaults Relationships Schedules Instances Lifecycle Collections Connections Delivery behaviorExpressions
Random
Random data is useful only when a failed test can be reproduced. Synthtraffic derives independent random streams from the scenario seed and the current generator, instance, event, and expression identity.
The result
This example fixes each range at one value so the function shapes are easy to see:
{"quantity":2,"price":19.99,"rating":4.5,"featured":true,"responseTime":"250ms"}
{"quantity":2,"price":19.99,"rating":4.5,"featured":true,"responseTime":"250ms"}
Generate product values
defaults:
seed: 42
generators:
- name: products
config:
maxEvents: 2
value:
quantity: =int(2, 2)
price: =uniform(19.99, 19.99, round=2)
rating: =normal(mean=4.5, sd=0, round=1)
featured: =bool(1)
responseTime: =uniformDuration(250ms, 250ms)
Use a wider range to get variation. The same scenario and seed reproduce the same sequence; changing the seed changes stochastic values.
int(min, max)
Returns an integer from min through max, including both endpoints. max must be greater than or equal to min.
age: =int(18, 65)
quantity: =int(1, 5)
With seed 42, three events:
{"age":45,"quantity":5}
{"age":37,"quantity":4}
{"age":18,"quantity":1}
float(min, max)
Returns a uniformly distributed floating-point number. float and uniform are aliases with the same implementation.
score: =float(0, 1, round=3)
With seed 42:
{"score":0.333}
uniform(min, max)
Returns a uniformly distributed number from min up to, but normally not including, max. When the bounds are equal, it returns that value. For duration strings, use uniformDuration.
amount: =uniform(100, 5000, round=2)
With seed 42:
{"amount":4288.89}
normal(mean, sd)
Returns a normally distributed number. sd is the standard deviation and must be zero or greater. Supply mean and sd either both positionally or both by name.
amount: =normal(mean=2500, sd=900, min=200, max=10000, round=2)
temperature: =normal(30, 3, round=1)
With seed 42:
{"amount":2959.21,"temperature":36.1}
min and max clamp the generated number before round is applied. They do not change the underlying distribution.
bool(probability?)
Returns a boolean. The default probability is 0.5; 1 always returns true, and 0 always returns false.
active: =bool()
isTrial: =bool(0.2)
With seed 42:
{"active":true,"isTrial":true}
string(length, alphabet?)
Returns a random string.
token: =string(16)
hexToken: =string(32, alphabet=hex)
pin: =string(6, alphabet=digits)
With seed 42:
{"token":"LrEFLmoPD6Aw3lXO","hexToken":"5ae7aea38d900b30592ee47c8008aa90","pin":"245316"}
Built-in alphabets: alpha, digits, alphanumeric, lower, upper, hex. Any other alphabet value is used literally as the character set.
bytes(size)
Returns random bytes. JSON encodes bytes as base64.
payload: =bytes(32)
With seed 42, JSON encodes the bytes as base64:
{"payload":"FZZeBhuyeiOG8Zhb2prm+RP7T4RBiA34L+cEiYlWWmE="}
size may be zero or greater. JSON encodes the resulting bytes as a base64 string.
uniformDuration(min, max)
Returns a duration string selected from the inclusive nanosecond range. Both arguments must be literal, non-negative durations and max must not be earlier than min.
latency: =uniformDuration(100ms, 500ms)
delay: =uniformDuration(1s, 5s)
With seed 42:
{"latency":"434.388096ms","delay":"2.62271097s"}
The result uses Go duration notation, such as 237ms or 1.5s. It can be used in payloads and duration-expression fields such as config.interval and delay.duration.
Shared options are function-specific. See Modifiers for the exact support matrix.