@Override
    public double logp(int k) {
        if (k < 0 || k > n) {
            return Double.NEGATIVE_INFINITY;
        } else {
            return lfactorial(n) - lfactorial(k)
                 - lfactorial(n - k) + k * log(p) + (n - k) * log(1.0 - p);
        }
    }
@Test
    public void testLogP() {
        System.out.println("logP");
        BinomialDistribution instance = new BinomialDistribution(100, 0.3);
        instance.rand();
        assertEquals(Math.log(3.234477e-16), instance.logp(0), 1E-5);
        assertEquals(Math.log(1.386204e-14), instance.logp(1), 1E-5);
        assertEquals(Math.log(1.170418e-06), instance.logp(10), 1E-5);
        assertEquals(Math.log(0.007575645), instance.logp(20), 1E-5);
        assertEquals(Math.log(0.08678386), instance.logp(30), 1E-5);
        assertEquals(Math.log(5.153775e-53), instance.logp(100), 1E-5);
    }