Posted in code thoughts
12:34 am, November 30, 2022

generate a random username function thoughts

I was looking though some of my functions to make more useful web tools from them and i came across the function for generating a username. 

I think originally i created this function to generate random usernames for comments so that the user did not have to select a username manually. 

I cant remember where i got the list from, but it seems to be quite duplicated.

How the function for username generation works?

  1. There is a string called usernames with names seperated by spaces.
  2. Then the names are added to an array using a string to array function. 
  3. There is another string with username prefixes
  4. The prefix string also gets added to an array
  5. There is a random function on the loop count to check how many usernames are added to the return string
  6. Count the total items in the username array
  7. Pick a random prefix from the array
  8. Enter the loop
    1. Shuffle the array
    2. Pick out an item from the array
    3. If prefixes are set then add a prefix
  9. Return the username

Keep it Simple or Make it more Complex?

When i was writing the tool for this i thought, oh i can add this to an api and return a username, but then i have to be able to specify how many names it returns, and then check the list of names that it generates from, should i add more names, where do i get the names from, should the names be in a database or just leave as a string.

It is better to leave it simple or does it benifit from making it more complex. 

Keep it simple for the initial tool page, and then make it more complex for the api version and release it on rapid an API to generate usernames.

View the Generate Random Username Tool

View Statistics
This Week
This Month
This Year

No Items Found.

Add Comment
Type in a Nick Name here
Other Items in code thoughts
Search Articles
Search Articles by entering your search text above.

This is my test area for webdev. I keep a collection of code here, mostly for my reference. Also if i find a good link, i usually add it here and then forget about it. more...

Subscribe to weekly updates about things i have added to the site or thought interesting during the last week.

You could also follow me on twitter or not... does anyone even use twitter anymore?

If you found something useful or like my work, you can buy me a coffee here. Mmm Coffee. ☕


🪦 2000 - 16 Oct 2022 - Boots
Random Quote
You want to be the best, you MUST put the long yards in! Nothing comes easy in life so stop wishing and start DOING! So many people would rather bitch and moan than help themselves. Dont be one of those negative drainers, start today, make a small change and keep going forwards with this attitude!
Random CSS Property


The grid-template-columns CSS property defines the line names and track sizing functions of the grid columns.
grid-template-columns css reference