37

I built a generative poster tool and the whole point was letting people share a seed so a friend gets the exact same artwork. First version used Math.random() everywhere, so of course nothing was reproducible and shared links rendered garbage.

The fix was demanding a single seeded PRNG threaded through every random call, plus a rule that no Date.now() or Math.random() sneak in. I also asked for the palette itself to be derived from the seed so the color story changes per poster but stays deterministic.

What's your favorite small PRNG for this? I landed on mulberry32 for the tiny code size.

THE PROMPT
Build a single-file HTML+canvas generative poster generator. Determinism is the hard requirement:
- Implement mulberry32 seeded from a `seed` integer parsed from the URL hash (default random on first load, then written back to the hash).
- Create ONE `rng()` closure and route EVERY random decision through it. BANNED: Math.random(), Date.now(), performance.now() for any visual value.
- Derive a 5-color palette from the seed using HSL with a golden-angle hue rotation (137.5 deg) so palettes feel harmonious but vary per seed.
- Composition: a 3x4 modular grid at 1000x1400, each cell gets one of {solid, diagonal-split, concentric-arcs, dot-matrix, stripes} chosen by rng, with 12% chance a shape spans two cells.
- Add subtle paper grain via a seeded noise overlay at low alpha.
- UI: a text input for seed and a 'randomize' button that just changes the hash; re-rendering the same seed must be pixel-identical.
Confirm in a comment that two loads of the same seed produce identical output and explain how you guaranteed it.
writing the seed back to the location hash so a reload is stable is the detail everyone forgets. shareable-by-default is the whole magic.onepromptwonder 1 month ago
add a comment

3 Answers

10

Golden-angle palettes are lovely but can wander into muddy olive territory. I constrain saturation and lightness to a small band and only let hue rotate, then reserve one 'accent' color at a jittered complementary hue. Instantly looks more art-directed.

THE PROMPT
Palette rule: fix S in [55,70] and L in [45,60] for 4 base colors rotated by 137.5deg, then add a 5th accent at (baseHue+180 + rng()*30) with higher saturation. Keeps it deterministic and stops the mud.
19

mulberry32 is the right call for size, but note it has a 2^32 period. Totally fine for posters. If you ever chain thousands of draws and see faint repetition, jump to a small xoshiro128** instead, same deterministic guarantees.

9

If you want print-quality output later, render to an offscreen canvas at 2x or 3x and downscale for display. Bake the DPR into the seed contract too, otherwise a retina user and a non-retina user get different grain from the same seed.

Your Answer