// Collection of code snippets by Arne Vajhøj 
// (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) 
import java.util.Random;

public class BinDist {
    private static Random rng = new Random();
    public static int dice() {
        return rng.nextInt() % 6;
    }
    public static int ones(int n) {
        int res = 0;
        for(int i = 0; i < n; i++) {
            if(dice() == 0) {
                res++;
            }
        }
        return res;
    }
    private static final int REP = 100000000;
    public static double[] dist(int n) {
        double[] res = new double[n+1];
        for(int i = 0; i < REP; i++) {
            res[ones(n)]++;
        }
        for(int i = 0; i <= n; i++) {
            res[i] /= REP;
        }
        return res;
    }
    public static long fac(long v) {
        if(v <= 1) {
            return 1;
        } else {
            return v * fac(v - 1);
        }
    }
    public static long comb(long n, long k) {
        return fac(n) / fac(k) / fac(n - k);
    }
    public static double prob(long k, long n, double p) {
        return comb(n, k) * Math.pow(p, k) * Math.pow(1 - p, n - k);
    }
    public static void main(String[] args) {
        double[] emp = dist(6);
        double accp = 0;
        for(int i = 6; i >= 0; i--) {
            double p = prob(i, 6, 1/6.0);
            accp += p;
            System.out.printf("%2d : %6.2f %6.2f %6.2f\n", i, emp[i] * 100, p * 100, accp * 100);
        }
    }
}
