Skip to content

Instantly share code, notes, and snippets.

@raszia
Created March 28, 2020 07:05
Show Gist options
  • Save raszia/9cbdc2ef265be88f4564a5aedf444555 to your computer and use it in GitHub Desktop.
Save raszia/9cbdc2ef265be88f4564a5aedf444555 to your computer and use it in GitHub Desktop.
Generate a valid and random iranian meli code
#!/usr/bin/python3
import random
import sys
def meli_code_generator():
while True:
meli_code = random.sample(range(1, 10), 9)
place_list = [10,9,8,7,6,5,4,3,2]
x = 0
for (a, b) in zip(place_list, meli_code):
x = x + (a*b)
remainder = (x % 11)
if x < 2:
last_number = remainder
elif x >= 2:
last_number = (11 - remainder)
if last_number < 10:
listToStr = ' '.join([str(number) for number in meli_code])
print(listToStr.replace(" ","")+str(last_number))
break
else:
pass
if __name__ == "__main__":
meli_code_generator()
@raszia
Copy link
Author

raszia commented Mar 28, 2020

Generate a valid and random iranian meli code

ساخت کد ملی معتبر به صورت اتفاقی

python meliGenerator.py

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