ipaddress
ipaddress copied to clipboard
Weighted sampling from multiple networks
The sample_ipv4(), sample_ipv6() and sample_network() functions support sampling addresses from a single network. When sampling from multiple networks, the current advice is to use an accept-reject algorithm. This is fine for generating IPv4 public addresses (~87% acceptance), but is computationally inefficient when the acceptance is low.
We could add a new function (or adjust sample_network()) to sample from a list of networks. By default, these networks would be sampled according to their size. But we could also allow the user to specify weightings.