This function generates one or more UUIDs (Universally Unique Identifiers).
By default, it generates Version 7 UUIDs, which are time-ordered and suitable
for use cases requiring efficient indexing and sorting by creation time.
Alternatively, random Version 4 UUIDs can be generated by setting usetime = FALSE
.
Details
Version 7 UUIDs: These are time-ordered UUIDs based on the current timestamp in milliseconds since the Unix epoch (
1970-01-01 00:00:00 UTC
). They are ideal for scenarios requiring chronological sorting or indexing.Version 4 UUIDs: These are randomly generated UUIDs that do not depend on time, ensuring uniqueness through random hexadecimal values.
Examples
library(pliman)
# Generate a single UUID
uuid()
#> [1] "af3a0b88-c9ae-435e-b1e9-ed1991423dd1"
# Generate 5 UUIDs in uppercase
uuid(n = 3, uppercase = TRUE)
#> [1] "4452077D-57DF-421E-ABFB-A769479E4F23"
#> [2] "0C8C16C2-E972-40E0-8F99-A419A7134DBB"
#> [3] "6C3332DE-454F-42BD-9B38-D45E66954B7A"
# Generate two random UUIDs
uuid(n = 2, usetime = FALSE)
#> [1] "ffa19a71-5504-4e4b-b58c-eb0083f17f6d"
#> [2] "f6fa9654-985d-4c7d-a2b9-f9ba19663bcb"