The following small code generates check digit for UPC-A codes. You can use it for example to generate random UPC-A codes.

#### Check digit calculation

The check digit is calculated as follows:

1. Add the digits in the odd-numbered positions together and multiply by three.

2. Add the digits in the even-numbered positions to the above result.

3. Find the result modulo 10 (i.e. the remainder when the result is divided by 10).

4. If the result is not zero, subtract the result from ten.

Read More