Hi,
I want to implement a weighted random sampling in Java, something like 'randsample' in matlab. Basically I have to implement
X(i) = randsample([0 1],1,true,[p1 p2]);
,
for n number of times where p1 and p2 are the probabilites of 0 and 1 which keep changing with every iteration(the function selectes either 0 and 1 based on p1 and p2).
Below is the code in Java that I have tried
Object[] population = { 0, 1 };
double[] weights = { p1, p2 };
Sampling randsamp = new Sampling(population, weights);
X[i] = (Integer) randsamp.next();
with this code I am getting random sampling but I am not sure if it is producing 0 and/or 1 based on the weights p1 and p2. also I cannot compare result with matlab since random function generates different number for every iteration.
Can someone tell me if the Java code is working same as Matlab or there is any other function in Java like 'randsample' in Matlab?
Thanks