Java Binomial Coefficients binomial(int n, double p)

Here you can find the source of binomial(int n, double p)

Description

binomial

License

Open Source License

Declaration

public static int binomial(int n, double p) 

Method Source Code

//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;
        }
    }
}

Related

  1. binomial(final int n, final int k)
  2. binomial(int n, final int k)
  3. binomial(int N, int K)
  4. binomial(int n, int k)
  5. binomialCdf(int k, int n, double p)