Luhn

2018-08-14  本文已影响0人  阴天有时下肉丸

Generate IMEI in python

#return luhn checksum:
def luhn_residue(digits):
    return sum(sum(divmod(int(d)*(1 + i%2), 10))
                 for i, d in enumerate(digits[::-1])) % 10

#generate valid number sequences
def getImei(N):
    part = ''.join(str(random.randrange(0,9)) for i in range(N-1))
    res = luhn_residue('{}{}'.format(part, 0))
    return '{}{}'.format(part, -res%10)
上一篇下一篇

猜你喜欢

热点阅读