f/code

A CF function to generate random usernames

I needed the ability to quickly generate a random username when a user signs up initially. Here is what I came up with.

	/**
	 * Generate a random, fun username (e.g. "fiery-minotaur", "gentle-panther-42").
	 * @includeNumber Append a random number at the end.
	 * @numberMax Max random number to append (if includeNumber).
	 * @hyphenated Use hyphens to separate words.
	 */
	public string function generateUsername(
		boolean includeNumber = true,
		numeric numberMax = 100,
		boolean hyphenated = true
	) {
		// LARGE adjective list
		var adjectives = [
			"ancient","agile","amber","arcane","atomic","august","auspicious","azure","brave","brazen",
			"bright","brisk","burning","calm","celestial","cerulean","chaotic","chromatic","clever","cosmic",
			"crimson","crystal","cunning","dauntless","dazzling","deep","dexterous","divine","drifting","dusky",
			"eager","electric","elemental","elusive","emerald","enchanted","epic","ethereal","fearless","feral",
			"fiery","fierce","fleet","floating","fluent","frozen","frosted","galactic","gentle","ghostly",
			"gilded","glacial","gleaming","gloomy","golden","grand","hidden","hollow","hyper","icy",
			"immortal","infinite","iron","jaded","jovial","keen","luminous","lunar","lush","magnetic",
			"mammoth","mighty","misty","molten","mystic","nameless","neon","noble","nocturnal","northern",
			"obsidian","oceanic","onyx","opal","orbital","phantom","pinnacle","plasma","prime","prismatic",
			"quiet","quicksilver","radiant","rapid","ravenous","reckless","restless","rigid","roaring","rough",
			"ruby","runic","sacred","scarlet","serene","shadow","shimmering","silent","silver","slumbering",
			"solar","sonic","spectral","spiral","spirit","splendid","spooky","steel","stellar","stormborn",
			"stormy","stranded","strange","sublime","swift","titanic","tranquil","twilight","ultra","uncanny",
			"velvet","vicious","vivid","vorpal","wandering","whispering","wild","winding","wired","wise",
			"wooden","wraith","zealous","zenith","zero","zinc","zonal"
		];

		// LARGE noun list
		var nouns = [
			"albatross","alpha","anvil","archer","asteroid","badger","bandit","basilisk","bear","beetle",
			"bison","blade","blizzard","bolt","buffalo","bull","cat","centaur","cerberus","chameleon",
			"cobra","comet","coyote","cricket","cyclone","daemon","dragon","drifter","eagle","ember",
			"falcon","ferret","flame","fox","gale","ghost","giant","glider","gnome","golem",
			"gorilla","griffin","guardian","hawk","hydra","jaguar","jester","juggernaut","keeper","kraken",
			"lion","lizard","mage","mammoth","manticore","mariner","meteor","minotaur","monarch","monkey",
			"nebula","nightblade","nightmare","nomad","nymph","octopus","ogre","onyx","oracle","otter",
			"owl","panther","pegasus","phantom","phoenix","pirate","puma","python","quartz","quokka",
			"ranger","raven","reaper","rhino","robot","ronin","sabertooth","sailor","serpent","shark",
			"shifter","slayer","sparrow","spider","sprite","stallion","storm","strider","tiger","torpedo",
			"turtle","unicorn","viper","vortex","warden","warlock","warrior","weasel","whale","wolf",
			"wyrm","wyvern","yeti","zephyr","zenmaster","zombie"
		];

		// Random selection
		var adj  = adjectives[ randRange(1, adjectives.len()) ];
		var noun = nouns[ randRange(1, nouns.len()) ];

		// Build username
		var username = "";

		if (hyphenated) {
			username = adj & "-" & noun;
			if (includeNumber) {
				username &= "-" & randRange(0, numberMax);
			}
		} else {
			username = adj & noun;
			if (includeNumber) {
				username &= randRange(0, numberMax);
			}
		}

		return lCase(username);
	}

Comments

No comments yet. Log in to start the conversation.

f/code

Code and anything code related

Created Dec 12, 2025

2
Members

Moderators
u/rob u/admin