mercredi 29 avril 2020

How to solve OverflowError when generating same random numbers between R and Python using SyncRNG

I am trying to reproduce R codes in Python and I have to generate same random numbers in both languages. I know that using the same seed is not enough to get same random numbers and reading one of the answers on this platform regarding this topic I have discovered that there exists: SyncRNG library, which generates same random numbers between R and Python. Everything looks fine as long as I have discovered that on Python 3.7.3 I can generate via SyncRNG just one number because as soon as you iterate the procedure, for instance, with a for loop you get this error:

OverflowError: Python int too large to convert to C long.

As I was mentioning:

>>> from SyncRNG import SyncRNG
>>> s = SyncRNG(seed=123)
>>> r = s.rand()
>>> r
0.016173338983207965

and as we can see it works. The method ".rand()" generates random numbers between zero and one. But if I try to iterate:

>>> from SyncRNG import SyncRNG
>>> s = SyncRNG(seed=123)
>>> b = []
>>> for i in range(5):
        temp = s.rand()
        b.append(temp)

and I get this:

OverflowError: Python int too large to convert to C long

So, I humbly ask if someone is able to solve this problem. If I lost old answers about this topic I'm sorry, please link them in the answer section. Thank you!




Aucun commentaire:

Enregistrer un commentaire