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] 81.170.233.86  22.117.127.199 123.18.240.66  111.201.77.131 78.138.93.115 

sample_ipv6(5)
#> <ip_address[5]>
#> [1] cdfb:3f73:7d52:f057:2f65:590f:e401:e480
#> [2] 2839:69af:2d56:ef6e:edef:adf:ea2d:7e7  
#> [3] fd70:9501:f5ba:9fe7:6134:cd8c:8b11:5a6 
#> [4] 2bc:193:c04f:3472:2b10:57c3:e309:379e  
#> [5] 82cf:bb6d:6542:7766:1e5a:6939:c84:af90 

sample_network(ip_network("192.168.0.0/16"), 5)
#> <ip_address[5]>
#> [1] 192.168.168.5   192.168.0.138   192.168.184.126 192.168.202.192
#> [5] 192.168.57.143 

sample_network(ip_network("2001:db8::/48"), 5)
#> <ip_address[5]>
#> [1] 2001:db8:0:f537:8217:232d:1328:f3a9 2001:db8:0:4359:4b7d:ed70:b820:fc0a
#> [3] 2001:db8:0:f889:56a7:15e6:34a:fee4  2001:db8:0:dabd:775e:7242:2e91:ad66
#> [5] 2001:db8:0:bad3:6be:fd8c:cf27:c879