prejo12

Generating ID numbers - How to generate last check digit number (using ADDLUHN(number))

Discussion created by prejo12 Employee on Jan 27, 2016

Hi all.

 

I was a little concerned with the complexity of generating SA ID numbers. The last number being a check digit number. By using the AddLuhn function, one is able to avoid all the complexity for generating the check digit number.

 

The logic for the ID number is as follows:

 

Example ID number: 82 05 21 5089 0 8 4

 

82 = YY Birth year

05 = MM Birth month

21 = DD Birth Day

5089 = Gender < 5000 = Female, >= 5000 = male <<< Use a random number generator. (left pad with 0s to make sure it is 4 characters long)

0 = Citizenship      0 = South African, 1 = Permanent resident 

8 = Used to be a racial identifier, now it is just a random digit

4 = Checksum number <<<This is where it gets a bit convoluted…

 

The checksum number is derived by:

  1. summing up all the odd digits:

8 + 0 + 2 + 5 + 8 + 0 = 23 Save this in variable A

  1. concatenating all the even digits:

concat(2,5,1,0,9,8) = 251098        Save in variable B

  1. double variable b

251098 * 2 = 502196 Save in Variable B

  1. Sum up all the individual numbers in variable B

5 + 0 + 2 + 1 + 9 + 6 = 23 Save in Variable B

  1. Sum A + B

23 + 23 = 46 Save in Variable C

  1. Find the value of the last digit that will make the full number a valid modulus 10 number:

Mod (1000 – Variable C, 10) = Mod (1000 – 96, 10) = Mod (9954, 10) = 4 <<< This is the last number of the ID number

----------------------------------------------------------------------------

In digging through the documentation I saw a function called AddLuhn(number) that takes care of creating the last checksum number.

 

Here is the complete logic to accomplish the above-mentioned logic:

@addluhn(@string(@dob(20,80,~SDATE~)@,YYMMDD)@@randdigits(4,4)@@randrange(0,1)@@randrange(0,9)@)@

 

Kind regards,

Johan

Outcomes