BigInteger.MulDivTest C# (CSharp) Method

MulDivTest() public static method

public static MulDivTest ( int rounds ) : void
rounds int
return void
        public static void MulDivTest(int rounds)
        {
                Random rand = new Random();
	        byte[] val = new byte[64];
	        byte[] val2 = new byte[64];

	        for(int count = 0; count < rounds; count++)
	        {
	                // generate 2 numbers of random length
		        int t1 = 0;
		        while(t1 == 0)
			        t1 = (int)(rand.NextDouble() * 65);

		        int t2 = 0;
		        while(t2 == 0)
			        t2 = (int)(rand.NextDouble() * 65);

		        bool done = false;
		        while(!done)
		        {
			        for(int i = 0; i < 64; i++)
			        {
				        if(i < t1)
					        val[i] = (byte)(rand.NextDouble() * 256);
				        else
					        val[i] = 0;

				        if(val[i] != 0)
					        done = true;
			        }
		        }

		        done = false;
		        while(!done)
		        {
			        for(int i = 0; i < 64; i++)
			        {
				        if(i < t2)
					        val2[i] = (byte)(rand.NextDouble() * 256);
				        else
					        val2[i] = 0;

				        if(val2[i] != 0)
					        done = true;
			        }
		        }

		        while(val[0] == 0)
		                val[0] = (byte)(rand.NextDouble() * 256);
		        while(val2[0] == 0)
		                val2[0] = (byte)(rand.NextDouble() * 256);

                        Console.WriteLine(count);
		        BigInteger bn1 = new BigInteger(val, t1);
		        BigInteger bn2 = new BigInteger(val2, t2);


                        // Determine the quotient and remainder by dividing
                        // the first number by the second.

		        BigInteger bn3 = bn1 / bn2;
		        BigInteger bn4 = bn1 % bn2;

		        // Recalculate the number
		        BigInteger bn5 = (bn3 * bn2) + bn4;

                        // Make sure they're the same
        		if(bn5 != bn1)
	        	{
		        	Console.WriteLine("Error at " + count);
                                Console.WriteLine(bn1 + "\n");
			        Console.WriteLine(bn2 + "\n");
			        Console.WriteLine(bn3 + "\n");
                                Console.WriteLine(bn4 + "\n");
			        Console.WriteLine(bn5 + "\n");
			        return;
		        }
	        }
        }