I'm trying to generate a random number in the range specified and then decide if its valid or not based on some simple arithmetic.

The sum (right after the DEBUG comment) is supposed to be, for example

222 222 222
121 212 121

(the 121 212 121 coefficients are added to each digit. if the product of the numbers is more than 9, then the sum of the digits of the product is recorded otherwise just the product is recorded (2*1 or 2*2 in this situation.)

using 222 222 222 as an example number the sum would be...

2*1 + 2*2 + 2*1 + 2*2 + 2*1 + 2*2 + 2*1 + 2*2 + 2\*1 = 26 in this situation.

The above operations are supposed to be made to the random number generated above, from the specified range. The problem is that this sum is incorrect, when checking it by hand. Please help...

```
   private void button1_Click(object sender, EventArgs e)
    {
        bool sinvalid = false;
        Random randomsin = new Random();
        //do until a valid sin is found
        do
        {
            int rsin = randomsin.Next(100000000, 799999999); //get a new random sin
            if (Validate(rsin.ToString()) == true) //if validate returns true
            {
                textBox1.Text = rsin.ToString(); //put the valid sin in the textbox
                sinvalid = true; //set current sin to valid
            }
        } while (sinvalid == false);
    }

    bool Validate(String sin)
    {
        int sum = Cdig(sin[0], 1) + Cdig(sin[1], 2) + Cdig(sin[2], 1) + Cdig(sin[3], 2) + Cdig(sin[4], 1) + Cdig(sin[5], 2) + Cdig(sin[6], 1) + Cdig(sin[7], 2) + Cdig(sin[8], 1);
        //DEBUG: show this sum, which is always calculated WRONG!~ WHY
        label1.Text = sum.ToString();
        if (sum % 10 == 0) //if sum is divisible by 10
        {
            return true;
        }
        else
        {
            return false;
        }
    }

    int Cdig(int dig, int n )
    {
        int dm = dig * n;

        if (dm > 9)
        {
            return 1 + (dm % 10);
        }
        else
        {
            return dm;
        }
    }

```