Equivalent of Matlab's “randsample” random sam

2019-07-12 15:49发布

问题:

Is there a function in Java like the randsample in Matlab which can return weighted samples(sampled uniformly at random with replacement, and having a weight- w[i] for each number. The probability that a number i is selected is w(i)/sum(w).)?

I want to use something like this

    randsample([0 1],1,true,[0.2 0.8]);

回答1:

You can look into the Apache Commons Math library. Specifically, it looks like you're interested in the Binomial Distribution.

Hope that helps!