When creating web apps, there’s often a need to generate a random password for your users. There are a number of ways to do this, but in needing to do this recently I came up with this very simple function that will generate a password (or other random string) of whatever length you wish.
The other day I was working on a project that required me to extract a numeric ID from the current page’s URL. The problem was that the ID could either be at the end of the URL string or in the middle, depending if there were any parameters added on or not. Here is how I worked around the problem by looping through each character of the string.