Here you can find the source of binomial(int n, double p)
public static int binomial(int n, double p)
//package com.java2s; //License from project: Open Source License public class Main { public static int binomial(int n, double p) { assert 0.0 <= p && p <= 1.0; int x = 0; for (int i = 0; i < n; i++) { x += bernouli(p);/*w ww . j a v a2 s . c o m*/ } return x; } public static int bernouli(double p) { assert 0.0 <= p && p <= 1.0; if (Math.random() < p) { return 1; } else { return 0; } } }