UUIDgenerate.RdUUIDgenerate generates new Universally Unique Identifiers. It
can be either time-based or random.
UUIDfromName generates deterministic UUIDs based on namespace
UUID and a name (UUID version 3 and 5).
UUIDparse parses one of more UUIDs in string form and converts
them to other internal formats.
UUIDvalidate checks the valitiy of UUIDs in string form.
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.
integer, number of UUIDs to generate.
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.
UUID defining the namespace
character vector of names to use for generating UUIDs. The result will yield as many UUIDs as there are elements in this vector.
string, type of the hash function to use when generating the UUIDs. "sha1" is recommended (version 5 UUID), "md5" is available for compatibility (version 3 UUID).
character vector which will be parsed into UUIDs.
UUIDgenerate, UUIDfromName 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").
The first argument is not n for historical reasons, because the
first version did only generate a single UUID.
Note that time-based UUIDs are not unique by design: two
UUIDs generated at exactly the same time will be identical by
definition and the underlying libuuid library can generate
duplicate time-based UUIDs if the CPU is fast enough. The
UUIDgenerate function always keeps track of the last
generated time-based UUID and will wait and repeat generation in
case the next requested UUID is identical, so the results from
UUIDgenerate(TRUE, ...) call will not include duplicates.
However, any other means of generating UUID (or calls to the C
API from parallel threads) do not offer that guarantee.
UUIDgenerate()
#> [1] "62bfe5b9-383c-4b00-9a5f-5a77c0c6bde7"
UUIDgenerate(TRUE)
#> [1] "2bfc4bda-4b06-11f0-8619-0242ac110005"
UUIDgenerate(FALSE)
#> [1] "246b4324-4b61-4314-8ab0-d4258f322d51"
## 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] "b39341b2-b946-42d9-a034-807d5c61050c"
#> [2] "4cd58a16-b3b7-43b1-a2be-e0c36bd4b535"
#> [3] "61c60e73-8ba8-4b5d-9677-f4756b5c101e"
as.character(u)
#> [1] "b39341b2-b946-42d9-a034-807d5c61050c"
#> [2] "4cd58a16-b3b7-43b1-a2be-e0c36bd4b535"
#> [3] "61c60e73-8ba8-4b5d-9677-f4756b5c101e"
as.raw(u[1])
#> [1] b3 93 41 b2 b9 46 42 d9 a0 34 80 7d 5c 61 05 0c
UUIDgenerate(output="raw")
#> [1] 4e 6b 1f 74 9c 56 4e f0 8b ab 26 3f 79 a2 42 ab
## UUID for DNS namespace
DNS.namespace <- "6ba7b810-9dad-11d1-80b4-00c04fd430c8"
## SHA1 (v5) - default
UUIDfromName(DNS.namespace, "r-project.org")
#> [1] "0cce4dd5-363b-5d7e-8baf-e5e06031f032"
## MD5 (v3)
UUIDfromName(DNS.namespace, "r-project.org", type="md5")
#> [1] "b9a02725-3dba-3d7c-81be-d05e0f134f8b"
## see ?UUID for more examples on UUID objects