Forum Discussion
larsn
7 years agoContributor
Read closely https://en.wikipedia.org/wiki/Luhn_algorithm - about verifying a number against the check digit which is the last digit. I created a function that generated a random number - one digit shorter than I needed, then ran the Luhn check to get the check digit and then appended that.
This example shows a function that returns the check digit in Java
https://github.com/nishan/luhn_java/blob/master/src/org/luhn/Luhn.java
FYI, here is another way to verify a number in Groovy
http://rosettacode.org/wiki/Luhn_test_of_credit_card_numbers#Groovy