imports Microsoft.VisualBasic
Dim FourDigitCode as string = "0612"
For i As Integer = 1 To 10
Dim num As String = CInt(Math.Ceiling(Rnd() * 9998)) + 1
num = num.PadLeft(4, "0")
Dim num2 As Integer = CInt(Math.Ceiling(Rnd() * 4)) + 1
Dim bc = "50000" & num2 & num & FourDigitCode
Console.WriteLine("Coupon: " & bc & Mod10CheckDigit(bc))
Public Function Mod10CheckDigit(Barcode As String) As Integer
For i = 1 To Len(Barcode) Step 2
TotalOdd = TotalOdd + (CInt(Mid(Barcode, i, 1)) * 1)
For i = 2 To Len(Barcode) Step 2
TotalEven = TotalEven + (CInt(Mid(Barcode, i, 1)) * 3)
Total = TotalOdd + TotalEven
Mod10CheckDigit = 10 - IIf(Microsoft.VisualBasic.Right(Total, 1) = 0, 10, _
Microsoft.VisualBasic.Right(Total, 1))