I have a simple java program that creates an array of random numbers. I am using rJava to call this program and create an R object. I know how to create random numbers in R ... I am trying to reproduce the results of a complicated java program exactly, which requires I use the same random numbers. Here is the java:
import java.util.Random;
public class rJava
{
public static void main(String[] args)
{
createRan();
}
public static double[] createRan()
{
int numSims = 100000;
int m_RandomSeed = 1234567;
Random m_Rnd = new Random(m_RandomSeed);
double[] randoms = new double[100000];
for(int i=0; i < numSims; i++)
{
randoms[i] = m_Rnd.nextDouble();
}
return randoms;
}
}
rJava seems to be working fine for me ... I use the following commands in R and an object called "rans" with 100000 random numbers is created.
library(rJava)
.jinit()
obj <- .jnew("rJava")
rans <- .jcall(obj, "[D", "createRan")
My problem is I went to change the size of the array for testing purposes to something more manageable, like 10 random numbers instead of 100,000. I saved and recompiled rJava.java, and re-ran the R code above. It still created an array of 100,000 numbers. I rebooted my computer and tried again ... still 100,000. I would ultimately like to pass a parameter into the java code to choose the number of random numbers to generate but would like to understand what is going on here first. I know very little about Java, is there some place where the initial state of rJava.java is stored and is being called from? As I said I have recompiled the class file so I would not the "original" would be overwritten.
Thanks