Posted in code thoughts
1764
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
52
This Month
232
This Year
648

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.
Welcome

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


James Clear
Random CSS Property

font-stretch

The font-stretch CSS descriptor allows authors to specify a normal, condensed, or expanded face for the fonts specified in the @font-face rule.
font-stretch (@font-face) css reference