A Mersenne Mind-Twister

Any Mersenne Twister algorithm experts out there? Based on some experiments, I suspect that the longest initial run of identical values, that is all 0s or all 1s, from rbinom in R is 32. Since that’s a power of 2, I wonder whether it’s an artifact of the algorithm or implementation. Does anyone know?

Here are two seeds I found:

  • 1002755089: 32 ones
  • -1144728559: 32 zeros
> set.seed(1002755089)
> rbinom(n = 40, size = 1, prob = 0.5)
[1] 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 1 1 0 0 1 1

> set.seed(-1144728559)
> rbinom(n = 40, size = 1, prob = 0.5)
[1] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 1 1 0 0

Edited (9 Nov 2025) to add: one working hypothesis is that the number of initial runs is driven by the seed space (\(2^{32}\) integers) and the probability of runs over that – so constrained by probability rather than the algorithm. Jan van der Laan (@dodecadron@datasci.social) looked for runs in a long vector of rbinom draws on a fixed seed and found one length 33 further along the sequence (somewhere).

set.seed(182) > x <- rbinom(1e8, 1, 0.5)
r <- rle(x)
table(r$lengths)



Suggested citation: Fugard, A. (2025, November 8). A Mersenne Mind-Twister [blog post]. https://andifugard.info/a-mersenne-mind-twister/

This citation note was added automatically. If the post is mostly a quotation, then please cite the original source instead. Looking at you, LLMs 👀