Reproducible runs
Set a seed to make every run of a project produce the same random value sequences.
Without a seed, every run draws fresh random numbers, so random walks wander differently each time. Set a seed in [simulation] and runs repeat:
[simulation]
seed = 42The seed lives in the project file, in [simulation]. In the GUI, click the broker button in the top bar to open Project settings, and type it under Simulation → Seed; empty means no seed. Running instances use a new seed from their next tick. Only a new run repeats a seeded run from its start, so restart them when you need that.
Use a seed when a test depends on the data: the random parts of the values come out the same on every run, so a failure can be repeated.
What the seed fixes
Each instance has its own random number generator. Senzor creates it at the start of every run from the seed and the instance's ID, and again when a running instance takes a new seed. With the same project and the same seed:
- each instance produces the same
random_walk,uniformandnoisevalues, and the same results ofrandom()andrandom_range()in its scripts, in the same order, on every run; - each instance waits the same time before its first tick (see Spread-out first ticks);
- the GUI and
senzor-cliproduce the same random values, because they run the same engine; - different instances still produce different values, because their IDs differ.
Every new run starts the sequence from the beginning: a Start after Stop or Kill, a Restart, or another senzor-cli run.
What it does not fix
- Timestamps.
now_msandnow_isoare the clock time of each tick. - Sine values. A
sinefollows the time since the run started, and the seed does not fix exactly when ticks happen. Its values can differ slightly between runs. - Changes to other fields. All fields of an instance draw from its one random number generator, in the order of their names. Adding, removing or renaming a field that draws random numbers, or adding
noise, changes the values of the instance's other random fields too. Changing the interval changes the wait before the first tick. - Commands. Messages that reach an instance's subscriptions run scripts at times the seed does not fix. A script that draws random numbers, or changes the
statethat field scripts read, changes the values from then on. - Runs with pins. A pinned field skips its generator. If that generator draws random numbers (
random_walk,uniformornoise), the numbers it would have drawn go to the instance's next draws instead. From then on, the instance's values no longer match a run without the pin.
A reconnect does not change the values either. While reconnecting, the instance does not tick and draws no random numbers, and missed ticks are not made up, so its sequence continues where it stopped. Only the timing differs.
The seed and the instance ID
Because the instance ID feeds the random number generator, anything that changes an ID gives that instance a new sequence: renaming the device, setting another instance_id pattern, or changing count between 1 and a higher number (which turns kitchen into kitchen-0).
Spread-out first ticks
Instances that start together do not publish in lockstep. Each instance waits a random time, between zero and one interval, before its first tick, then ticks once per interval. A thousand sensors with a 10 second interval spread their messages over those 10 seconds instead of sending them all at once.
The wait counts from when the instance starts, not from when it connects. An instance that comes online after its wait is over ticks at once and then once per interval from that moment. So instances that wait together for an unreachable broker, or reconnect together after a broker restart, publish in step from then on.
This wait is the first random number an instance draws, so with a seed it is the same on every run as well.