Skip to content

Instantly share code, notes, and snippets.

@Alireza2n
Forked from omidp/nationalCodeGenerator.java
Last active August 17, 2024 09:53
Show Gist options
  • Save Alireza2n/5708c361ca8417dec0f355d8eb51bc2b to your computer and use it in GitHub Desktop.
Save Alireza2n/5708c361ca8417dec0f355d8eb51bc2b to your computer and use it in GitHub Desktop.
تولید کننده کد ملی در پایتون
def national_code_generator():
number_list = []
_sum = 0
out = ""
for i in reversed(range(2, 11)):
_j = random.randint(0, 9)
number_list.append(str(_j))
_sum += _j * i
_m = _sum % 11
if _m < 2:
number_list.append(str(_m))
elif _m >= 2:
number_list.append(str(11 - _m))
return out.join(number_list)
@Alireza2n
Copy link
Author

Alireza2n commented Aug 26, 2017

برای استفاده در کاربرد های تست اپ ها
unit test, factory_boy, etc.

با تشکر از http://kpnu-csc.ir/forum/-php/3255-a-post12409.html#post12409

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment