This article mainly studies the sampling or sampling of binomial distributions in Java programming. The following is the specific implementation code.
The following program is a binomial distribution sampling with n=100 and p=0.9, with a total of 10,000 samples.
package function;import org.apache.commons.math3.distribution.BetaDistribution;import org.apache.commons.math3.distribution.BinomialDistribution;import org.apache.commons.math3.special.Gamma;public class dergamma {//sample 1000 times public static void main(String[] args) {for (int i = 0; i < 1000; i++) {System.out.println(binomialsampler(100,0.9));}}//binomial distribution sampling public static double binomialsampler(int trials, double p){BinomialDistribution binomial=new BinomialDistribution(trials,p);return binomial.sample();}}As shown in the figure below, the result of each sampling:
The graph of the distribution is as follows:
Summarize
The above is the entire content of this article about Java programming to implement sampling or sampling instance code for binomial distribution. I hope it will be helpful to everyone. Interested friends can continue to refer to other related topics on this site. If there are any shortcomings, please leave a message to point it out. Thank you friends for your support for this site!