Skip to content

SpecificationI · Overview

1.4

Determinism: the same program always gives the same result

With the same program, the same inputs and the same seed, the engine always produces the same output, on any computer.

Markdown version

1.4.1 How it works

A program is deterministic if exactly the same thing happens every time you run it. In PseudoLearn this is a guarantee: the output, the way it ends, the diagnostics and the trace are identical on a phone, a laptop or in the browser.

To make that possible, the engine controls everything that could vary:

  • Randomness comes from a source with a seed. Same seed, same sequence of numbers.
  • Concurrent tasks take turns in a fixed order.
  • The clock, files and network are requested as capabilities and can be recorded and replayed.
  • Memory is reclaimed without the program being able to notice.
Figure 1.4-1.Two runs with the same seed produce the same sequence. Changing the seed changes the numbers, not the rules.

A box with seed 42 from which two runs leave. Both produce the sequence 1, 1, 6 and an equals sign joins them.

This specification is always built with seed 42. That is why this program writes the same numbers every time:

ProgramThree dice rolls

Algorithm Dados
  Write randomBetween(1, 6), " ", randomBetween(1, 6), " ", randomBetween(1, 6);
EndAlgorithm

Output

1 1 6

The program finishes normally.

In short

  • Same program, same inputs and same seed: same result.
  • Randomness comes from a seeded source.
  • Tasks, clock, files and network are controlled so as not to break determinism.
  • Memory reclamation cannot be observed.