A system is deterministic if, given the same input and the same starting state, it always produces the same output. A system is non-deterministic if it doesn't โ either by design or by accident.
Most engineers think everything they build is deterministic. Most of it isn't.
Pure Determinism
A pure function: f(x) = y. Always. No exceptions. No side effects, no external state, no timing dependency.
Integer arithmetic โ 3 + 5 = 8. On every machine. Every time.
Hash function โ SHA-256 of "hello" is the same on every CPU on earth
Sorting a list with a stable sort โ same input order โ same output order
State machines โ given state S and input I, the next state is always S'
Determinism is the foundation of testing, debugging, and reasoning about software. When it breaks, everything gets harder.
Designed Non-Determinism: On Purpose
Sometimes you want different outputs. The randomness is a feature.
Random Number Generation
Pseudo-random (PRNG) โ deterministic given a seed, but appears random. Reproducible if you save the seed.
True random (TRNG/CSPRNG) โ sourced from hardware entropy (thermal noise, timing jitter). Genuinely unpredictable. Used in cryptography.
AI Model Sampling
The model outputs probabilities. Sampling picks one outcome. Temperature controls how much the model explores vs exploits.
Intentional variation โ you want different responses to the same prompt. Creativity requires non-determinism. See how AI works.
Load balancers โ distribute requests randomly or round-robin. Which server handles your request is non-deterministic by design.
Monte Carlo simulations โ use randomness to explore probability spaces. The answer is statistical, not exact.
Randomised algorithms โ quicksort with random pivot, randomised consensus protocols. Randomness improves average-case performance or breaks symmetry.
Accidental Non-Determinism: The Bugs You Can't See
This is where systems that should be deterministic aren't. Not because you chose randomness โ because the universe leaked in.
Floating-point arithmetic โ different hardware, different rounding, different results
Thread scheduling โ which thread runs first depends on OS state. Race conditions produce different outcomes on each run
Network ordering โ packets arrive in different orders. Distributed systems see different event sequences
Wall-clock time โ anything depending on timestamps, timeouts, or "now" is non-deterministic
Hash map iteration order โ many languages don't guarantee order. Same data, different iteration sequence
Memory allocation โ addresses vary between runs (ASLR, heap state). Pointer-based ordering changes
GPU parallelism โ thread execution order varies. FP accumulation order varies. Results vary.
Concurrency: The Biggest Source
The moment you have two threads, two processes, or two machines, determinism is gone unless you explicitly enforce it.
Race Condition
Two threads read a counter, both see 5, both write 6. The counter should be 7. This is non-deterministic โ the outcome depends on which thread runs first, which changes every execution.
Message Ordering
Service A sends messages to B and C. B processes faster and replies before C. Next time, C is faster. The system's behaviour depends on arrival order โ which is determined by network latency, CPU load, GC pauses, and cosmic rays.
Distributed Systems: Non-Determinism as Physics
In distributed systems, non-determinism isn't a bug. It's the fundamental operating condition.
No global clock โ "what happened first?" has no universal answer
Partial failure โ some nodes crash, others don't. The system is in a state that no single node can fully observe
Network partitions โ two halves of the system evolve independently, then must reconcile
Eventual consistency โ different nodes see different values for the same data. Temporarily. Maybe.
The entire field of distributed consensus (Paxos, Raft, PBFT) exists because the physical world is non-deterministic and you need to synthesise agreement from chaos.
Quantum: Fundamental Non-Determinism
At the bottom of the stack, physics itself is non-deterministic. Quantum measurement is genuinely random โ not "we don't know the hidden variable" random, but "there is no hidden variable" random.
A quantum bit exists in superposition until measured. The outcome is probabilistic. No seed. No hidden state. This is the only true source of non-determinism in the universe โ everything else is just complexity we can't track.
The Spectrum
Fully deterministic โ pure functions, integer maths, state machines
Deterministic with seed โ PRNGs, AI with fixed seed + greedy sampling
Deterministic in theory, not in practice โ FP arithmetic, GPU computation
Non-deterministic by environment โ threads, network, time, OS scheduling
Non-deterministic by design โ sampling, randomised algorithms, load balancers
Fundamentally non-deterministic โ quantum measurement
Most real systems live in the middle โ deterministic at the instruction level, non-deterministic at the system level. The gap between those two is where bugs live.
Determinism is not a property of computers. It's a property of specific computations running under specific conditions. The moment you add concurrency, networks, or floating point, you've left the deterministic world. Most software lives outside it and pretends otherwise.
Determinism is a constraint on the wavefunction. Remove it, and the system explores. Enforce it, and the system collapses to a single path. Most interesting systems need both โ deterministic components composed into non-deterministic wholes.