[Go] Generate a random UUID

Created on November 30, 2026

Use uuid.New() from github.com/google/uuid to generate a random version 4 UUID. In a Go module, add the package with go get github.com/google/uuid.

package main

import (
    "fmt"

    "github.com/google/uuid"
)

func main() {
    u := uuid.New()
    fmt.Println(u.String())
}

The value changes on each run. This is one possible result.

d54359da-0551-447b-bee2-3475122614ff
Go