Alternative random id generation to uuid

randid

import "go.withmatt.com/randid"

id := randid.New().String()

randid's goals are simple: a smaller, more compact, faster version of uuid4. I don't care about the actual format of a UUID, I just want some random id.

comparison with uuid4

  • randid is full 128 bits, and uuid4 is 122
  • randid is base64 encoded, uuid4 is hex with hyphens
  • randid string length is 22, and uuid4 is 32
 uuid4: 3cf6702a-da2a-4456-8a53-80a235b3cbfd
randid: cKTij4eSRWmIFgydqgi_Ww

benchmarks

goos: linux
goarch: amd64
pkg: go.withmatt.com/randid
cpu: 11th Gen Intel(R) Core(TM) i7-1165G7 @ 2.80GHz
BenchmarkNew
BenchmarkNew-8                   1462352               827.4 ns/op            16 B/op          1 allocs/op
BenchmarkUUIDNew
BenchmarkUUIDNew-8               1458153               833.9 ns/op            16 B/op          1 allocs/op
BenchmarkNewString
BenchmarkNewString-8             1418264               842.0 ns/op            16 B/op          1 allocs/op
BenchmarkUUIDNewString
BenchmarkUUIDNewString-8         1370332               872.0 ns/op            64 B/op          2 allocs/op

As we can see, just the New() path in comparison to uuid4 is marginally faster, since we're not throwing away extra random bits.

On the New().String() path, we gain a bit more performance and 1 less memory allocation, as well as a smaller allocation needed.

Owner
Matt Robenolt
πŸ•πŸ•πŸ•πŸ•πŸ•πŸ•πŸ•πŸ•πŸ•πŸ•πŸ•πŸ•πŸ•πŸ•πŸ•πŸ•πŸ•πŸ•πŸ•πŸ•πŸ•πŸ•πŸ•πŸ•πŸ•πŸ•πŸ•πŸ•πŸ•πŸ•πŸ•πŸ•πŸ•πŸ•πŸ•πŸ•πŸ•πŸ•πŸ•πŸ•πŸ•πŸ•πŸ•πŸ•πŸ•πŸ•πŸ•πŸ•πŸ•πŸ•πŸ•πŸ•πŸ•πŸ•πŸ•πŸ•πŸ•πŸ•πŸ•πŸ•πŸ•πŸ•πŸ•πŸ•πŸ•πŸ•πŸ•πŸ•πŸ•πŸ•πŸ•πŸ•πŸ•πŸ•πŸ•πŸ•πŸ•πŸ•πŸ•πŸ•
Matt Robenolt
Similar Resources

A UUID package originally forked from github.com/satori/go.uuid

UUID Package uuid provides a pure Go implementation of Universally Unique Identifiers (UUID) variant as defined in RFC-4122. This package supports bot

Dec 30, 2022

An extremely fast UUID alternative written in golang

Overview WUID is a globally unique number generator, while it is NOT a UUID implementation. WUID is 10-135 times faster than UUID and 4600 times faste

Dec 9, 2022

An extremely fast UUID alternative written in golang

Overview WUID is a globally unique number generator, while it is NOT a UUID implementation. WUID is 10-135 times faster than UUID and 4600 times faste

May 10, 2021

Uber-cute UUID's alternative !

UwUID β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β €β € ⠀⠀⠀⣿⣿⑆⠀⠀Ⓒ⣷⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀Ⓒ⣿⑇⠀⠀⣾⣿⑆⠀ ⠀⠀⠀⣿⣿⑇⠀⠀Ⓒ⣿⒰⣿⑆⠀⣾⣿⑆⠀

Jul 22, 2022

generate random data like name, email, uuid, address, images and etc.

gg-rand generate random data like name, email, uuid, address, images and etc. build and install: make run: gg-rand $ gg-rand SillyName : Knavesa

Nov 16, 2022

A Go Library For Generating Random, Rule Based Passwords. Many Random, Much Secure.

A Go Library For Generating Random, Rule Based Passwords. Many Random, Much Secure.

Can Haz Password? A Go library for generating random, rule based passwords. Many random, much secure. Features Randomized password length (bounded). T

Dec 6, 2021

Random is a package written in Go that implements pseudo-random number generators for various distributions.

Random This package implements pseudo-random number generators for various distributions. For integers, there is a function for random selection from

Jul 11, 2022

Go-random-chat - Fast and scalable real-time random chat written in go

Go-random-chat - Fast and scalable real-time random chat written in go

Go Random Chat Fast and scalable real-time random chat written in go. Features:

Dec 21, 2022

Random - A Golang library that provides functions for generating random values

Random A Golang library that provides functions for generating random values. Us

Dec 15, 2022

Automatic Service Mesh and RPC generation for Go micro services, it's a humble alternative to gRPC with Istio.

Automatic Service Mesh and RPC generation for Go micro services, it's a humble alternative to gRPC with Istio.

Mesh RPC MeshRPC provides automatic Service Mesh and RPC generation for Go micro services, it's a humble alternative to gRPC with Istio. In a nutshell

Aug 22, 2022

The open source public cloud platform. An AWS alternative for the next generation of developers.

The open source public cloud platform. An AWS alternative for the next generation of developers.

M3O M3O is an open source public cloud platform. We are building an AWS alternative for the next generation of developers. Overview AWS was a first ge

Jan 2, 2023

A multi-pass compiler written in Go comprised of scanner, recursive-descent parser, generation of AST, intermediate representation (ILOC), and code generation (Armv8).

GoLite Project - Go Huskies! This is a project conducted and led in the course MPCS 51300 Compilers at the University of Chicago. In a group of two, w

Jan 10, 2022

UUID package for Go

UUID package for Go language This package provides pure Go implementation of Universally Unique Identifier (UUID). Supported both creation and parsing

Jan 2, 2023

A lightweight UUID implementation

uuid uuid is a lightweight implementation for Univerally unique identifier. Usage var id UUID = uuid.Rand() fmt.Println(id.Hex()) fmt.Println(id.Raw()

Feb 25, 2020

Library to integrate github.com/google/uuid with gopkg.in/vmihailenco/msgpack

Library to integrate github.com/google/uuid with gopkg.in/vmihailenco/msgpack

Apr 26, 2022

golang uuid-shellcodeεŠ θ½½ε™¨,εˆ†η¦»ζ‰§θ‘Œ,可直ζŽ₯把shellcode写ε…₯程序。

golang uuid-shellcodeεŠ θ½½ε™¨,εˆ†η¦»ζ‰§θ‘Œ,可直ζŽ₯把shellcode写ε…₯程序。

Jan 7, 2023

A simple uuid library based on RFC 4122

UUID generator A simple library that generates uuids. Supported versions: version 1 version 3 version 4 version 5 Supported variants: DCE Microsoft Th

Oct 20, 2021

Postgres uuid[] field for gorm.io - Golang

Postgres uuid[] field for gorm.io - Golang

Jan 17, 2022

Generate UUID for script's sql

Generate UUID for script's sql Instale o go em sua maquina https://golang.org/doc/install Baixe as seguintes dependecias go get github.com/satori/go.u

Oct 26, 2021
An extremely fast UUID alternative written in golang

Overview WUID is a globally unique number generator, while it is NOT a UUID implementation. WUID is 10-135 times faster than UUID and 4600 times faste

Dec 9, 2022
An extremely fast UUID alternative written in golang

Overview WUID is a globally unique number generator, while it is NOT a UUID implementation. WUID is 10-135 times faster than UUID and 4600 times faste

May 10, 2021
UUID package for Go

UUID package for Go language This package provides pure Go implementation of Universally Unique Identifier (UUID). Supported both creation and parsing

Jan 2, 2023
A lightweight UUID implementation

uuid uuid is a lightweight implementation for Univerally unique identifier. Usage var id UUID = uuid.Rand() fmt.Println(id.Hex()) fmt.Println(id.Raw()

Feb 25, 2020
Library to integrate github.com/google/uuid with gopkg.in/vmihailenco/msgpack

Library to integrate github.com/google/uuid with gopkg.in/vmihailenco/msgpack

Apr 26, 2022
A simple uuid library based on RFC 4122

UUID generator A simple library that generates uuids. Supported versions: version 1 version 3 version 4 version 5 Supported variants: DCE Microsoft Th

Oct 20, 2021
Generate UUID for script's sql

Generate UUID for script's sql Instale o go em sua maquina https://golang.org/doc/install Baixe as seguintes dependecias go get github.com/satori/go.u

Oct 26, 2021
UUID package for Golang

UUID package for Go language This package provides pure Go implementation of Universally Unique Identifier (UUID). Supported both creation and parsing

Dec 9, 2021
Generate, encode, and decode UUIDs v1 with fast or cryptographic-quality random node identifier.

A Go package for generating and manipulating UUIDs Generate, encode, and decode UUIDs v1, as defined in RFC 4122, in Go. Project Status v1.1.0 Stable:

Sep 27, 2022
A UUIDv4 generation package written in go

Goid A Go package to generate V4 UUIDs Documentation The API docs can be viewed here or generated with godoc. Usage An example of generating a v4 UUID

Dec 24, 2022