Skip navigation
Help

DrupalTestCase::randomString

7 drupal_web_test_case.php public static DrupalTestCase::randomString($length = 8)

Generates a random string of ASCII characters of codes 32 to 126.

The generated string includes alpha-numeric characters and common misc characters. Use this method when testing general input where the content is not restricted.

Parameters

$length: Length of random string to generate.

Return value

Randomly generated string.

10 calls to DrupalTestCase::randomString()

File

drupal/modules/simpletest/drupal_web_test_case.php, line 549

Code

public static function randomString($length = 8) {
  $str = '';
  for ($i = 0; $i < $length; $i++) {
    $str .= chr(mt_rand(32, 126));
  }
  return $str;
}