 # How to generate Luhn Algorithm(AKA Mod10) unique Number every time in UIpath?

for ex - please refer this link. https://www.dcode.fr/luhn-algorithm for generating Mod10 number.

Hi,

First, we can check it using the following expression.

``````(String.Join("",strDigits.Reverse.Select(Function(c,i) (CInt(c.ToString) << (i mod 2)).ToString)).Sum(Function(c) Cint(c.ToString)) mod 10)=0
``````

Note: It’s assumed strDigits contains only digit characters.

Next, if we want to generate check digit character, the following step will work.

``````strDigits ="123456789"
master = {New String(){"0","9","8","7","6","5","4","3","2","1"},New String(){"0","9","4","8","3","7","2","6","1","5"}}
modValue = (String.Join("",strDigits.Reverse.Select(Function(c,i) (CInt(c.ToString) << (i mod 2)).ToString)).Sum(Function(c) Cint(c.ToString))) mod 10
``````

Then

``````master(strDigits.Length mod 2)(modValue)+strDigits
``````

Regards,

Hi,

If we want to create unique number with check digit, the following will work.

Main.xaml (7.4 KB)

Regards,

thanks made small change to generate strictly 10 digits & it is working fine. String.Join("",Enumerable.Range(0,9).Select(Function(i) rnd.Next(0,9).ToString))

Main.xaml (7.5 KB)

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.