Forum Discussion
sanj
Super Contributor
here are few useful links
https://gist.github.com/mdp/9691528
approach to java and groovy would be very similar
https://stackoverflow.com/questions/20740444/check-credit-card-validity-using-luhn-algorithm
jwindrum
7 years agoNew Contributor
Hi Sanj,
I am looking to create the data, rather than validate it. There really are not a lot of resources specific to creation that I've found. One of my coworkers had created a Google app script to generate the data so that it can be used in Sheets, and I've extracted the script, but am having one heck of a time converting it to Groovy.
function RanSin () { for (;;){ var n=9, sum=0, rn, ranSin, nextDigit, total=0; var evenDigit = false; while (n>0){ rn = Math.floor(Math.random()*(9-1))+1; sum+=rn; if ( n == 1){ break; } sum*=10; n-=1; } ranSin=sum; while ( ranSin > 0 ) { nextDigit = ranSin %10; ranSin = Math.floor(ranSin / 10); if (evenDigit) { nextDigit = 2* nextDigit; nextDigit = Math.floor(nextDigit / 10) + (nextDigit % 10); } total += nextDigit; evenDigit = !evenDigit; } if ( 0 == (total%10)){ return sum; break; } } }