Posted in code thoughts
1730
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
47
This Month
198
This Year
614

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
I believe that success can be measured in the number of uncomfortable conversations you're willing to have.
Unknown
Random CSS Property

padding-left

The padding-left CSS property sets the width of the padding area to the left of an element.
padding-left css reference