Skip to contents

sample_ipv4() and sample_ipv6() sample from the entire address space; sample_network() samples from a specific network.

Usage

sample_ipv4(size, ..., replace = FALSE)

sample_ipv6(size, ..., replace = FALSE)

sample_network(x, size, ..., replace = FALSE)

Arguments

size

Integer specifying the number of addresses to return

...

These dots are for future extensions and must be empty.

replace

Should sampling be with replacement? (default: FALSE)

x

An ip_network scalar

Value

An ip_address vector

See also

Use seq.ip_network() to generate all addresses in a network.

Examples

sample_ipv4(5)
#> <ip_address[5]>
#> [1] 95.242.70.52  7.138.145.182 119.139.85.16 99.71.152.90  5.114.49.211 

sample_ipv6(5)
#> <ip_address[5]>
#> [1] 3897:ffaf:a967:915b:df81:d08c:2666:9960
#> [2] ba3c:9c3e:dbc5:40c6:2a9:67d5:8436:428f 
#> [3] 37e8:2c0b:ed1e:eb95:e383:3707:d8ab:4adb
#> [4] 74d1:e8e8:8d31:dea2:ffd5:6b78:b70f:7a62
#> [5] 55b3:912:932a:3fdb:80b5:abce:3dff:eb87 

sample_network(ip_network("192.168.0.0/16"), 5)
#> <ip_address[5]>
#> [1] 192.168.209.145 192.168.231.64  192.168.148.118 192.168.197.234
#> [5] 192.168.254.249

sample_network(ip_network("2001:db8::/48"), 5)
#> <ip_address[5]>
#> [1] 2001:db8:0:c736:f2e7:527c:15aa:3db6 2001:db8:0:4935:37c5:5c3f:db68:137 
#> [3] 2001:db8:0:e00a:862:e3af:1359:f14a  2001:db8:0:4bf1:25ff:d329:dabc:70b8
#> [5] 2001:db8:0:fb3e:da59:19f3:1baa:c0dd