To choose an ip address from 127.0.0.0/8 subnet randomly in Python 3:
>>> import ipaddress
>>> import random
>>> ipaddress.IPv4Address('127.0.0.1') + random.randrange(2**24 - 2)
IPv4Address('127.23.181.175')