Luhn

作者: 阴天有时下肉丸 | 来源:发表于2018-08-14 10:51 被阅读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)

    相关文章

      网友评论

          本文标题:Luhn

          本文链接:https://www.haomeiwen.com/subject/eapmbftx.html