def get_imei(n):
    def luhn_residue(digits):
        """Luhn algorithm"""
        return sum(sum(divmod(int(d) * (1 + i % 2), 10))
                   for i, d in enumerate(digits[::-1])) % 10

    part = ''.join(str(random.randrange(0, 9)) for _ in range(n - 1))
    res = luhn_residue('{}{}'.format(part, 0))
    return '{}{}'.format(part, -res % 10)
Random IMEI generator. This function return random but not unique
dataset/ETHPy150Open allegro/ralph/src/ralph/data_importer/management/commands/demodata.py/get_imei