-3

Im trying to code a personal identificational number which should have 10 numbers. It looks like this 990830/4197. First two numbers - year - 1999 he was born Second two numbers - month - august Third two numbers - day 3O.8 Last 4 numbers are generated that way so the whole number when you take it has to be devided by 11 and there cant remain any number. So for example; 99+8+30+4197= 4 334 /11 = 394. Always the number should be % = 0. I wanna ask for some key words that might help me when I wanna generate correct numbers. Thanks

  • Welcome to SO. Refer [How to ask a question on SO](https://stackoverflow.com/help/mcve) – Sociopath Nov 21 '18 at 09:43
  • 3
    i cant really understand what the question is here. " wanna ask for some key words" is not specific. can you show what you have done and what problem you face. – MEdwin Nov 21 '18 at 09:44
  • It is always useful for us to see some code. Also, it feels better to know that you have tried already something yourself and asks us what you may have done incorrectly or what you may have missed. Plus, formulate a clear and distinct question which one could highlight also if it is not already in your title. – Alex_P Nov 21 '18 at 09:47

1 Answers1

0

I am assuming here that the date part of the number you have already. Then you can use this code to calculate the "tail" efficiently:

from random import randint


date = 990830


s = sum(int(x) * 10**(i % 2) for i, x in enumerate(str(date), 1))  # note 1
tail = randint(90, 908) * 11 - (s % 11)  # note 2

print('{}\{}'.format(date, tail))

which produces (several examples):

990830\5462
990830\5132
990830\8751
990830\6397

with all of them being perfectly divisible by 11.


  1. This simply adds the numbers of the date as described (e.g., 99 + 08 + 30)
  2. This calculates a random 4 digit number that when added to the above sum creates a number N for which N % 11 == 0.
Ma0
  • 15,057
  • 4
  • 35
  • 65