#native_company# #native_desc#
#native_cta#

Generate a random string.

By Matthew Harris
on October 21, 2005

Version: 0.1

Type: Function

Category: Algorithms

License: GNU General Public License

Description: Generate a random string based on a supplied length and seed.

// Generates a 4 character random string,
// using the seed ‘abcd’
$randomStr = getRandomStr(4, ‘abcd’);

<?php
  function getRandomStr($length = 6, $seed = 'abcdef0123456789')
  {
    for ($str = '', $i = 0; $i < $length; ++$i)
      $str .= $seed{rand(0, strlen($seed) - 1)};

    return $str;
  }
?>