Q:

c# - How to generate random ITIN

How to generate an 9 digit ITIN number with 70-88 in the fourth and fifth digit? 

The IRS site says that 
An Individual Taxpayer Identification Number (ITIN) begins with the number 9 and has a range of **70-88 in the fourth and fifth digit.  The range was extended to include 900-70-0000 through 999-88-9999, 900-90-0000 through 999-92-9999 and 900-94-0000 through 999-99-9999. 

My test is to validate that an error message is seen when user tries to input a valid ITIN
My code is checking for fourth and fifth digit after getting a random number.  
A better way would be to get a random number with 9xx-70-0000 to 9xx-88-9999
        int RangeOneBoundaryStart = 70;
        int RangeOneBoundaryEnd = 88;       
        int count = 100;
        string InvalidMsg = "Invalid Entry.  Individual Tax Identification Numbers are not accepted."; 

        Random rand = new Random();

        for (int i = 1; i <=count; i++ )
        {
            int Rndm1 = rand. Next(900700000, 999889999);
            string num = Rndm1.ToString();                
            string chcknum = num. Substring(3, 2);
            int chcknumint = Int32.Parse(chcknum);

            if ( chcknumint >= RangeOneBoundaryStart && Rndm1 < RangeOneBoundaryEnd)
            {
                _applyPage. ClearField(VerifyElement);
                _applyPage. EnterTextWithValue(VerifyElement, num);
                _applyPage. Click(ClickAnotherElement);
                _TestMethods. ValidateError(ElementToVld, InvalidMsg);
            }            

        }

A:

You could generate 3 different random numbers. 
var rnd = new Random();
var rnd3 = rnd. Next(900, 1000); // 900 <= x < 1000 
var rnd2 = rnd. Next(70, 89); // 70 <= x < 89
var rnd4 = rnd. Next(0, 10000); // 0 <= x < 10000

and then something like to generate the itin. 
var itin = rnd3 + "-" + rnd2 + "-" + rnd4.ToString("0000");

https://dotnetfiddle.net/CpoWAq

