How to Generate a Random String

The Text::random() method returns a random string of the type and length that is requested. The type of random strings that can be requested are:

  • alnum : All letters and numbers
  • alpha : Only letters, upper and lower case
  • hexdec : Base 16 hexadecimal symbols ( 0123456789abcdef )
  • numeric : Numbers Only
  • nozero : Numbers but without any zeros
  • distinct : Numbers but with no zeros and upper case letters
Usage
  echo Text::random('alnum', 8);
  echo Text::random('alpha', 10);
  8Sf45xHX
  NAWpNXeljF
how_to_generate_a_random_string.txt · Last modified: 2009/10/15 21:16 by kerkness