One thing that occurs quite frequently when developing for the web is random string generation. That is, generating a string of a specific length consisting of random elements from a given set, be it characters, numbers etc. Some of the numerous applications of random string generation are:

  • CAPTCHA string generation, and
  • Password generation for new users

We even use random string generation here at Glass Obelisk! Gotxt, our website that allows you to send free sms’ generates a random string of numbers when a new user signs up for an account in order to prevent fraud and spam. As an aside, challenging a user to verify a randomly generated string is a great way to verify email accounts.

Now that you know about the advantages of random string generation, we can progress to implementation details. Because of the necessity of random string generation, we have created a PHP class that you may use to your liking, pursuant to terms of the BSD License (included with the source code).

The functionality comes encapsulated in an easy to use class and is very extensible. Instructions as per extensibility are included in the source code. Usage instructions have also been uploaded for your convenience.

If you have any questions or comments don’t hesitate to post them.

Happy Coding.

Random String Generation Class

How to use the random string generation class