Dev Hub Solutions

Product studio

Get in touch

Generate UUID v4 and v7 in C#

Copy-paste C# code that produces a UUID v4 (random, the long-standing default) or UUID v7 (time-ordered, the modern choice for database keys). Both blocks below are production-ready.

UUID v4 in C#

v4 is purely random — 122 bits of entropy, no structure. Use it when you don't want timing information embedded in the ID, or when you don't care about index locality.

using System;

class Program {
    static void Main() {
        Guid id = Guid.NewGuid(); // v4
        Console.WriteLine(id);
    }
}

UUID v7 in C#

v7 embeds a millisecond Unix timestamp in the first 48 bits, so the IDs sort chronologically. This is what modern databases want from a primary key — sequential inserts land in adjacent index pages instead of scattering writes.

// .NET 9 (November 2024) ships Guid.CreateVersion7():
using System;

class Program {
    static void Main() {
        Guid id = Guid.CreateVersion7();
        Console.WriteLine(id);
    }
}

Library support

.NET 9 introduced `Guid.CreateVersion7()` natively. For .NET 8 and earlier, use the `UUIDNext` NuGet package (`UuidV7.NewUuid()`).

Notes

`Guid` in .NET is the equivalent of a UUID. `NewGuid()` was already cryptographically random in .NET Framework 4.0+; .NET 9 added the v7 ordering variant.

Need them in bulk?

Our UUID generator produces 1 to 1000 UUIDs (v4 or v7) instantly, all in your browser, with one-click copy and JSON/CSV export. Useful for seeding test data or pre-generating IDs offline.