How to Create Random Bank Account Number

In earlier days, bank accounts were maintained on ledgers. After that, the account numbers were consecutive. Yet after automation, the category of accounts have altered the account number structure as a result of multiple CBS application and organization procedure of the private financial institutions.

In general, the consist of the account number is as below.

1. Bank Code

2. Branch Code

3. Product Code

4. Extn Code

5. Account Number

Based upon this, a chequing account of product kind 3xx opened at the 6xx branch would resemble this: 6xx-3xx-1234-RNG.

Obviously, various banks will have their own method of numbering accounts. It's normally a combination of those things mentioned.

Then, how do banks generate account numbers for their clients? The numbers seem so arbitrary. There need to be some formula. It seems that you can use the Random class to generate the numbers. See the following sample code.

public static IEnumerable<int> BANS
        int[] digits = { 1, 0, 0, 0, 0, 0, 0, 0, 2 };

        int carryFlag = 0;
            int sum = digits.Select((d, i) => d * (9 - i))

            if (sum % 11 == 0)
                yield return digits.Aggregate(0, (accumulator, digit) => accumulator * 10 + digit);

            int digitIndex = digits.Length - 1;
                digits[digitIndex] += 1;
                if (digits[digitIndex] == 10)
                    digits[digitIndex--] = 0;
                    carryFlag = 1;
                    carryFlag = 0;
            while (digitIndex >= 0 && carryFlag == 1);
        while (carryFlag == 0);

        yield break;

In addition, the check digit is included as an issue the safety measure to avoid mistakes like feeding the account number wrongly. If the number is input mistakenly, the program runs a confirmation routine that recalculates the check figure and compares it to the input check number. If it matches after that the purchase is allowed; Else, it is declined with a suitable message.

Leave a reply