usernaemgen

package module
v2.0.1 Latest Latest
Warning

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

Go to latest
Published: Aug 8, 2025 License: MIT Imports: 3 Imported by: 0

README

username_r_gen

A pseudo random username generator.

Dictionary Unique Count
Adjectives 325
Colors 148
Animals 535
Total 325 x 148 x 535 = 25,733,500 Possible combination (with out postfix)

[!NOTE] Using a type of Postfix like UseProvidedNumber or UseProvidedNumberAfterOverflow would paricaly make the conflicts nearly impossible


How to use

nameGenerator := usernaemgen.NewUsernameGen()
uniqueName := nameGenerator.Generate(1)
fmt.Println(uniqueName) // cute-blue-fox

[!Tip] The algorithm is optimized for serialized number usage. So, if you have the user's ID, you should use it rather than an arbitrary number. For example, you can use the auto-generated ID from your database (id AUTOINCREMENT/SERIAL PRIMARY KEY)

Or use the GenerateRand() fn
nameGenerator := usernaemgen.NewUsernameGen()
uniqueName := nameGenerator.GenerateRand()
fmt.Println(uniqueName) // nervous-Gold-hornbill-551536555
You can customize the dictionaries, delimiter, and postfixType
nameGenerator := usernaemgen.NewUsernameGenWithOptions(
	"__",
	usernaemgen.NoPostfix,
	usernaemgen.Adjectives,
	usernaemgen.Animals,
)
uniqueName := nameGenerator.GenerateRand()
fmt.Println(uniqueName) // great__canary
You can change the order of the dictionaries
nameGenerator := usernaemgen.NewUsernameGenWithOptions(
	"-",
	usernaemgen.NoPostfix,
	usernaemgen.Animals, // <-- will start from animals rather then adjectives liken in the previous examples
	usernaemgen.Colors, // <-- then colors
	usernaemgen.Adjectives, // <-- and finish with the adjectives
)
uniqueName := nameGenerator.GenerateRand()
fmt.Println(uniqueName) // cat-blue-angry

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DictsLen [numDicts]int

Functions

func NewUsernameGen

func NewUsernameGen() *usernameGen

func NewUsernameGenWithOptions

func NewUsernameGenWithOptions(delimiter string, postfixType PostfixType, dicts ...DictType) *usernameGen

Types

type DictType

type DictType byte
const (
	// Adjective word list.
	Adjectives DictType = iota
	// Color word list.
	Colors DictType = iota
	// Animal word list.
	Animals DictType = iota
)

type PostfixType

type PostfixType byte
const (
	// Do not use any postfix
	NoPostfix PostfixType = iota

	// Use the provided number as postfix for the result in
	// case the number overflows the total possible values
	UseProvidedNumberAfterOverflow PostfixType = iota

	// Use the provided number as postfix for the result
	UseProvidedNumber PostfixType = iota
)

Jump to

Keyboard shortcuts

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