I need a function to generate random numbers from a seed across multiple computers using different languajes. I want to know if there is a common function in the libraries of C, Python, Java and R that, using the same seed, gives the same random numbers. If not, what is the best option to achieve this?
Asked
Active
Viewed 59 times
0
-
Use one language's RNG and interface with that language from the other languages. – Roland Nov 10 '20 at 09:01
-
You can write your own PRNG function (there are plenty of algorithms to be found) and implement it in each language you need. – Weather Vane Nov 10 '20 at 09:51
-
If it were me and I wanted to avoid wasting precious development time and effort, I would get an **existing** library that properly implements the same algorithm (MT or LCG as suggested in the dupe). I would not make bridges between languages or start writing my own (possibly buggy) implementations unless absolutely necessary. – Kayaman Nov 10 '20 at 10:01
-
@Kayaman Unless someone has done the work for you and interfaced the library with all languages (that's possible), you'll have to do that yourself. I don't think you will find that for the Mersenne Twister (because there are so many different versions of it). – Roland Nov 10 '20 at 10:18
-
@Roland I didn't mean the same *library*. I meant the same algorithm. The MT discrepancy is discussed in the dupe, but it should be a lot less work to get 4 libraries for 4 languages and verify that they use the same algorithm and provide the same results than writing your own things. At least for the very common languages given in the question. – Kayaman Nov 10 '20 at 10:25
-
@Kayaman Personally, I'd think it would be easier (and require less knowledge about RNGs) to interface all languages mentioned by OP with R than conclusively testing and comparing four libraries. But to each their own. – Roland Nov 10 '20 at 11:08