Skip to content

A pseudo-random username generator that uses a predefined List of words(adjectives, colors, animals) to generate a unique username

License

Notifications You must be signed in to change notification settings

Nidal-Bakir/username_r_gen

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

A pseudo-random username generator that uses a predefined List of words(adjectives, colors, animals) to generate a unique username

Topics

Resources

License

Stars

Watchers

Forks

Languages