Are we rolling the same dice? PRNG Consistency Across R and Python

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.

Authors

Institutions

Publication Details

Journal
Scatterplot
Published
2026-06-25
DOI
https://doi.org/10.1080/29932955.2026.2693442
Primary Topic
Cardiomyopathy and Myosin Studies
Type
article
Field-Weighted Citation Impact
0.00
Controls
|||
ALL TIME
JAN
FEB
MAR
APR
MAY
JUN
JUL
AUG
SEP
OCT
article

Are we rolling the same dice? PRNG Consistency Across R and Python

Ramón A. Mata-Toledo, Kathleen Ryan, Sarah Dumnich, Adam Gilbert
Scatterplot
Cardiomyopathy and Myosin Studies
article

Are we rolling the same dice? PRNG Consistency Across R and Python

Ramón A. Mata-Toledo, Kathleen Ryan, Sarah Dumnich, Adam Gilbert
article en

Abstract

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.

Scatterplot
James Madison University (US), Saint Vincent College (US), Southern New Hampshire University (US), DeSales University (US)
Openalex Percentile: Top 8%
Cardiomyopathy and Myosin Studies
AI Navigator

Ask Laika to Summarize, Analyze, and Connect papers live on the map.

Summarize Papers & Methodologies

Extract key findings, datasets, and comparative methods across publications.

Benchmark Rankings & Visual Analytics

Rank top research institutions, authors, funders, topics, and journals by Field-Weighted Citation Impact (FWCI) and paper volume with instant charts.

Connect Distant Disciplines

Bridge topological clusters on the map to find hidden collaborative intersections.