Mersenne Twister and PCG produce different integer streams across R and Python despite statistically indistinguishable distributions, whereas XorShift128+ sequences would be identical.
Pseudo-random number generators (PRNGs) are widely used in simulations, statistical modeling, and machine learning. While they offer reproducibility and efficiency, differences in implementation across programming languages can lead to inconsistencies, particularly in collaborative, cross-language workflows. In this study, we compare random sequences generated using Mersenne Twister (MTA) in R and Python, and examine two additional PRNGs: the Permuted Congruential Generator (PCG) and XorShift128+ implemented in Python. Our results show that while MTA produces different sequences across languages, their distributions are statistically indistinguishable. We also identify that PCG produces sequences that follow the same distribution as MTA but it generates different integer streams across the two languages as well. In our implementation of XorShift128+, we find that these sequences are statistically indistinguishable from those generated using MTA and would be identical across R and Python. These findings highlight the importance of understanding PRNG behavior in multi-language settings and caution against assuming equivalence based solely on algorithm names. We conclude by highlighting the reticulate package, which allows for objects generated in an R or Python environment to be pulled over to the other environment, ensuring exact consistency.
Dumnich et al. (Thu,) reported a other. Pseudo-random number generators (MTA, PCG, XorShift128+) vs. Cross-language comparison (R vs Python) was evaluated on Sequence consistency and distribution equivalence. Mersenne Twister and PCG produce different integer streams across R and Python despite statistically indistinguishable distributions, whereas XorShift128+ sequences would be identical.