public static int random(double[] prob) {
        int[] ans = random(prob, 1);
        return ans[0];
    }
@Test
    public void testRandom() {
        System.out.println("random");
        double[] prob = {0.473646292, 0.206116725, 0.009308497, 0.227844687, 0.083083799};
        int[] sample = MathEx.random(prob, 300);
        double[][] hist = Histogram.of(sample, 5);
        double[] p = new double[5];
        for (int i = 0; i < 5; i++) {
            p[i] = hist[2][i] / 300.0;
        }
        assertTrue(MathEx.KullbackLeiblerDivergence(prob, p) < 0.05);
    }