Example #1
0
    private static void test03()

    //****************************************************************************80
    //
    //  Purpose:
    //
    //    TEST03 tests COMB by generating 10 random 3-subsets of a 25 set.
    //
    //  Licensing:
    //
    //    This code is distributed under the GNU LGPL license.
    //
    //  Modified:
    //
    //    01 April 2016
    //
    //  Author:
    //
    //    John Burkardt
    //
    {
        int       j;
        const int k = 3;
        const int n = 25;

        int lmax = FullertonLib.i4_binom(n, k);

        Console.WriteLine("");
        Console.WriteLine("TEST03");
        Console.WriteLine("  Generate 10 random K-subsets of an N set.");
        Console.WriteLine("  K = " + k + "");
        Console.WriteLine("  N = " + n + "");
        Console.WriteLine("  LMAX =" + lmax + "");

        if (!typeMethods.i4_choose_check(n, k))
        {
            Console.WriteLine("");
            Console.WriteLine("TEST03 - Warning!");
            Console.WriteLine("  The binomial coefficient cannot be");
            Console.WriteLine("  computed in integer arithmetic for");
            Console.WriteLine("  this choice of parameters.");
            return;
        }

        Console.WriteLine("");

        int seed = 123456789;

        for (j = 1; j <= 10; j++)
        {
            int    l    = UniformRNG.i4_uniform_ab(1, lmax, ref seed);
            int[]  c    = Comb.comb(n, k, l);
            string cout = "  " + l.ToString().PadLeft(4) + ":  ";
            int    i;
            for (i = 0; i < k; i++)
            {
                cout += "  " + c[i].ToString().PadLeft(4);
            }

            Console.WriteLine(cout);
        }
    }