27 lines
1.1 KiB
Markdown
27 lines
1.1 KiB
Markdown
# [proposal: crypto/rand: add UUIDv4 and UUIDv7](https://golang.org/issue/76319)
|
|
|
|
This package is an implementation of the crypto/rand API amended as proposed by #76319.
|
|
|
|
```go
|
|
// UUIDv4 generates a RFC 9562 Version 4 UUID
|
|
// using only random bytes in the format:
|
|
// xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx.
|
|
func UUIDv4() string
|
|
|
|
// UUIDv7 generates a RFC 9562 Version 7 UUID
|
|
// using the current time and random bytes in the format:
|
|
// xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx.
|
|
func UUIDv7() string
|
|
```
|
|
|
|
The UUID functions forward to github.com/google/uuid.
|
|
The rest forward to crypto/rand.
|
|
Unless you are changing the value of rand.Reader, this package a drop-in replacement for crypto/rand.
|
|
|
|
This is an ergonomics test.
|
|
Most other UUID packages define `[16]byte` types, but #76319 proposes to add functions that return only the string forms of UUIDs.
|
|
You can use this package to check whether the proposed API works (better?) for you.
|
|
|
|
There are questions that have been raised about the proposed API, especially with regard to the clock component of v7 UUIDs.
|
|
This package does not address those.
|