randomSeed() makes a p5.js sketch's random output deterministic so results can be saved, shared, and re-created
p5.js random() uses a pseudo-random number generator seeded from the clock by default, so each run produces different results. Calling randomSeed(n) before a sequence of random() calls produces the identical sequence every time for the same n. This is essential for: saving and sharing outputs (same seed recreates the image), interactive exploration (click to try a new seed without losing the previous one), and debugging (pin a seed to investigate a visual anomaly). A common misapplication is seeding once at setup() but then calling random() elsewhere before the sequence of interest — the seed sets the starting position in the PRNG stream, so any intervening call shifts all subsequent results.
Examples
var actRandomSeed = 42; randomSeed(actRandomSeed); // before loop — same line every time. On mouse click: actRandomSeed = random(100000); // try a new seed. M_1_1_01 demonstrates this with a random chart.
Assessment
Explain why two calls to randomSeed(42) before the same random() sequence produce identical results. Modify a sketch to display the current seed so a user can copy and share their favourite output.