public function Drush_TestCase::randomString

6.x public Drush_TestCase::randomString($length = 10)
5.x public Drush_TestCase::randomString($length = 10)

Helper function to generate a random string of arbitrary length.

Copied from drush_generate_password(), which is otherwise not available here.


$length: Number of characters the generated string should contain.

Return value

The generated string.

1 call to Drush_TestCase::randomString()
siteInstallD6Case::testExtraConfigurationOptions in tests/siteIntallD6Test.php
Test a D6 install with extra options.


tests/, line 166
Initialize a sandboxed environment. Starts with call unish_init() at bottom.




public function randomString($length = 10) {
  // This variable contains the list of allowable characters for the
  // password. Note that the number 0 and the letter 'O' have been
  // removed to avoid confusion between the two. The same is true
  // of 'I', 1, and 'l'.
  $allowable_characters = 'abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ23456789';

  // Zero-based count of characters in the allowable list:
  $len = strlen($allowable_characters) - 1;

  // Declare the password as a blank string.
  $pass = '';

  // Loop the number of times specified by $length.
  for ($i = 0; $i < $length; $i++) {

    // Each iteration, pick a random character from the
    // allowable string and append it to the password:
    $pass .= $allowable_characters[mt_rand(0, $len)];

  return $pass;