UUIDgenerate generates new Universally Unique Identifiers. It can be either time-based or random.

UUIDparse parses one of more UUIDs it string form and converts them to other internal formats.

UUIDvalidate checks the valitiy of UUIDs in string form.

UUIDgenerate(use.time = NA, n = 1L, output = c("string", "raw", "uuid"))
UUIDparse(what, output = c("uuid", "string", "raw", "logical"))
UUIDvalidate(what)

Arguments

use.time

logical, if TRUE then time-based UUID is generated, if FALSE then a random UUID is generated, if NA then random one is generated if a sufficiently reliable source of random numbers can be found, otherwise a time-based UUID is generated.

n

integer, number of UUIDs to generate.

output

type of the output. Valid types are: "string" for a character vector with UUIDs in textual representation (always lowercase), "raw" for a vector or matrix of raw bytes, "uuid" for an object of the class UUID and "logical" which only reports failure/success of the parsing, but not the actual values.

what

character vector which will be parsed into UUIDs.

Value

UUIDgenerate and UUIDparse values depend on the

output argument as follows:

"string"

character vector with each element UUID in lowercase form, for UUIDparse strings that cannot be parsed will result in NA values

"raw"

raw vector with the UUIDs stores each as 16 bytes seqeuntially. If the output is more than one UUID then the result is a raw matrix with 16 rows and as many columns as there are input elements.

"uuid"

object of the class UUID which is a vector of UUIDs in 128-bit internal representation.

"logical"

only supported in UUIDparse and return code TRUE for valid UUID, FALSE for invalid input and NA for NA input.

UUIDvalidate is just a shorthand for

UUIDparse(what, output="logical").

Author

Simon Urbanek, based on libuuid by Theodore Ts'o.

Note

The first argument is not n for historical reasons, beause the first version did only generate a single UUID.

Examples

UUIDgenerate()
#> [1] "aaf401f1-8b01-4ce6-9c05-9ce5028ee693"
UUIDgenerate(TRUE)
#> [1] "d6ac37ce-3cae-11ee-ad82-0242ac110004"
UUIDgenerate(FALSE)
#> [1] "e8d49787-fe8e-4c7e-a858-9d032120ef76"

## see if the randomness is any good
length(unique(UUIDgenerate(n=1000)))
#> [1] 1000

## generate a native UUID vector
(u <- UUIDgenerate(n=3, output="uuid"))
#> UUID vector:
#> [1] "7a012ebc-21ea-4581-a635-33e553fb4b02"
#> [2] "3d8ce746-9c85-4a1a-95a7-0cc4e818629e"
#> [3] "ba8687e7-fdd4-4f94-8c1d-494ef80f9bac"

as.character(u)
#> [1] "7a012ebc-21ea-4581-a635-33e553fb4b02"
#> [2] "3d8ce746-9c85-4a1a-95a7-0cc4e818629e"
#> [3] "ba8687e7-fdd4-4f94-8c1d-494ef80f9bac"
as.raw(u[1])
#>  [1] 7a 01 2e bc 21 ea 45 81 a6 35 33 e5 53 fb 4b 02

UUIDgenerate(output="raw")
#>  [1] 8d 58 9a 63 b6 2a 46 48 8d c0 03 ed 0b 59 23 e6

## see ?UUID for more examples on UUID objects