From Wikipedia:
PESEL is the national identification number used in Poland since 1979. It always has 11 digits, identifies just one person and cannot be changed to another one.
It has the form of YYMMDDZZZXQ, where YYMMDD is the date of birth (with century encoded in month field), ZZZ is the personal identification number, X denotes sex (even number for females, odd number for males) and Q is a control digit, which is used to verify whether a given PESEL is correct or not.
Having a PESEL in the form of ABCDEF GHIJK, one can check the vailidity of the number by computing the following expression:
A*1 + B*3 + C*7 + D*9 + E*1 + F*3 + G*7 + H*9 + I*1 + J*3
Then the last digit of the result should be subtracted from 10. If the result of the last operation is not equal to the last digit of a given PESEL, the PESEL is incorrect. This system works reliably well for catching one-digit mistakes and digit swaps.
Provide a short program to generate random, valid PESEL number:
- It has to be a PESEL a person born in either 20th or 21st century
- The birth birth date has to be random but doesn't have to validate leap years or number of days in a month (i.e. the numbers representing the day number have to be between
01
and31
) - All valid PESELs in this date range (01.01.1990-31.12.2099) must be possible
- The shortest code (i.e. complete program code), in bytes, wins.
10
. The Polish Wikipedia version uses a modulo 10 operation to get 0 in this case. \$\endgroup\$0
to9
to encode male and female (1 bit). What's the purpose of this "random noise"? Or are there further specification on the gender field that I have missed? \$\endgroup\$