package module
Version: v1.0.1 Latest Latest

This package is not in the latest version of its module.

Go to latest
Published: Apr 10, 2019 License: Apache-2.0 Imports: 7 Imported by: 351



License Apache 2 ReportCard Build Status Release GoDoc Coverage Status

A highly performant unique identifier generator.


Use the go command:

$ go get

Basic Usage

// Utilize the global locked instance
nuid := nuid.Next()

// Create an instance, these are not locked.
n := nuid.New()
nuid = n.Next()

// Generate a new crypto/rand seeded prefix.
// Generally not needed, happens automatically.


NUID needs to be very fast to generate and be truly unique, all while being entropy pool friendly. NUID uses 12 bytes of crypto generated data (entropy draining), and 10 bytes of pseudo-random sequential data that increments with a pseudo-random increment.

Total length of a NUID string is 22 bytes of base 62 ascii text, so 62^22 or 2707803647802660400290261537185326956544 possibilities.

NUID can generate identifiers as fast as 60ns, or ~16 million per second. There is an associated benchmark you can use to test performance on your own hardware.


Unless otherwise noted, the NATS source files are distributed under the Apache Version 2.0 license found in the LICENSE file.



A unique identifier generator that is high performance, very fast, and tries to be entropy pool friendly.



View Source
const Version = "1.0.1"

Version of the library


This section is empty.


func Next

func Next() string

Generate the next NUID string from the global locked NUID instance.


type NUID

type NUID struct {
	// contains filtered or unexported fields

func New

func New() *NUID

New will generate a new NUID and properly initialize the prefix, sequential start, and sequential increment.

func (*NUID) Next

func (n *NUID) Next() string

Generate the next NUID string.

func (*NUID) RandomizePrefix

func (n *NUID) RandomizePrefix()

Generate a new prefix from crypto/rand. This call *can* drain entropy and will be called automatically when we exhaust the sequential range. Will panic if it gets an error from rand.Int()

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL