Home

Awesome

Nano ID for C

<img src="logo.svg" align="right" alt="Logo" width="180" height="94">

A tiny, secure, URL-friendly unique string ID generator for C.

#include <nanoid.h>
#include <stdio.h>

int main() {
  char *id = NANOID();

  if (id) {
    puts(id);
    free(id);
  }
}
$ cc main.c -o example
$ ./example
V1StGXR8_Z5jdHi6B-myT

Overview

A Nano ID is a unique string ID where each character is an alphanumeric, a hyphen, or an underscore. Think of it as a random unpadded Base64url string. You've already seen this ID format elsewhere: on YouTube.

By default, a Nano ID is 21 characters long. 6 bits of entropy per character, 126 bits per ID.

Setup

Works out of the box on NetBSD, OpenBSD, Linux, Android, macOS, iOS, illumos, FreeBSD, DragonFly, Haiku, Fuchsia, WASI, and Emscripten. Windows support requires a getentropy(3) shim.

To build just nanoidgen(1), run make nanoidgen. No Makefile required.

Usage

nanoid(3)

#include <nanoid.h>

nanoidgen(1)

nanoidgen [length]

Attribution

Port of Nano ID by Andrey Sitnik.

Original logo by Anton Lovchikov.

Social preview background texture by Tuomo.

Social preview logo assistance by Tanya Nevskaya.