Each of the N particles is given a random velocity whose x, y and z components are drawn from a Gaussian with the same width — the direct consequence of the equipartition theorem, which assigns each degree of freedom an average energy of ½kT. The resulting distribution of speeds (not velocity components) is the classic Maxwell–Boltzmann curve, shown live against the measured histogram. Particles never interact with each other, only with the walls, so the demo isolates two independent statistical-mechanics ideas: the shape of the speed distribution set by temperature, and the entropy increase of free expansion set by volume.
f(v) = sqrt(2/π) · v² / σ³ · exp(−v² / 2σ²), σ² = kT/m
S/k = − Σᵢ pᵢ ln pᵢ (Shannon entropy over spatial bins)
- Particles — how many gas molecules are tracked; more particles make the measured histogram converge more tightly onto the theoretical curve.
- Temperature — sets σ, the standard deviation of each velocity component; raising it shifts the whole speed distribution to higher values and speeds up the visible motion.
- Simulation speed — a clock multiplier so slow diffusion after the partition drops is easier to watch.
- Remove/insert partition — the classic "free expansion" experiment: with the wall in place the gas is confined to the left half (low entropy, ordered); removing it doubles the accessible volume and the spatial entropy climbs toward its new maximum as the gas explores the whole chamber, with no work done and (for an ideal, non-interacting gas) no change in temperature.
Real-world relevance: this is the textbook derivation behind why entropy is a measure of the number of accessible microstates, not of "disorder" in a vague sense — it is exactly this free-expansion argument (ΔS = Nk·ln(V₂/V₁)) that sets the sign of the second law and explains why gases never spontaneously recompress into half a room.