Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Generating the same random number in Java and Python

Tags:

java

python

Is it possible to generate the same random number in python as in java if given the same seed

Explained in a more accurate way, Is it possible to use the linear congruential formula from java in Python?

like image 379
Delusional Logic Avatar asked Jun 22 '12 19:06

Delusional Logic


2 Answers

Have you taken a look at this project? http://pypi.python.org/pypi/java-random

like image 58
Jordan Avatar answered Oct 17 '22 02:10

Jordan


Using Pyjnius:

from jnius import autoclass

rand = autoclass('java.util.Random')()

rand.setSeed(12345)

print(rand.nextInt(50))
print(rand.nextInt(50))
print(rand.nextInt(50))
print(rand.nextInt(50))
like image 32
nog642 Avatar answered Oct 17 '22 03:10

nog642