Studio 137 · Field Notes

The Shape of Randomness

When you call random.randint() in Python, a tiny seed like 12345 becomes a field of 624 numbers. Each call reads one word from that field, runs it through a bit-scrambler, and moves on. When the field is exhausted, it twists itself into a new one. This is MT19937 — the Mersenne Twister — and it is entirely deterministic. Watch it run.

Seed

Try: 0, 1, 12345, 137, 2147483647

Step

index = 624 / 624 · drawn = 0

Internal State — 624 words of 32 bits

next word to consumelast word consumedhover a cell for its hex value

Tempering — raw state → output

Draw a number to see the raw state word get scrambled into the output, one xor at a time.

Recent outputs

No outputs yet.

How a small seed becomes 624 words

The seeding routine is a one-line recurrence:

mt[0] = seed
for i in 1..623:
  mt[i] = (1812433253 * (mt[i-1] ^ (mt[i-1] >> 30)) + i) mod 2^32

That one multiply-xor-add, iterated 623 times, turns any 32-bit number into the entire colored grid above. Change the seed by one and every cell changes. Seed with 0 and the first outputs are still different from 1 — not because of any entropy source, but because the recurrence diverges immediately.

Note: this page uses the canonical reference seeder init_genrand(n) from Matsumoto & Nishimura's mt19937ar.c. Python's random.seed(n) uses a different expansion (init_by_array) so the exact numbers will differ from Python, but the algorithm and state layout are identical.