src/Alo.php
public static function asciiRand($length, $subset = self::ASCII_ALL) {
            switch ($subset) {
                case self::ASCII_ALPHANUM:
                    $subset = self::$asciiAlphanum;
                    break;
                case self::ASCII_NONALPHANUM:
                    $subset = self::$asciNonAlphanum;
                    break;
                default:
                    $subset = array_merge(self::$asciiAlphanum, self::$asciNonAlphanum);
            }

            $count = count($subset) - 1;

            $r = '';

            for ($i = 0; $i < $length; $i++) {
                $r .= $subset[mt_rand(0, $count)];
            }

            return $r;
        }
public static function asciiRand($length, $subset = self::ASCII_ALL) {
            switch ($subset) {
                case self::ASCII_ALPHANUM:
                    $subset = self::$asciiAlphanum;
                    break;
                case self::ASCII_NONALPHANUM:
                    $subset = self::$asciNonAlphanum;
                    break;
                default:
                    $subset = array_merge(self::$asciiAlphanum, self::$asciNonAlphanum);
            }

            $count = count($subset) - 1;

            $r = '';

            for ($i = 0; $i < $length; $i++) {
                $r .= $subset[mt_rand(0, $count)];
            }

            return $r;
        }
public static function asciiRand ( $ length , $ subset = self :: ASCII_ALL ) { switch ( $ subset ) { case self :: ASCII_ALPHANUM : $ subset = self :: $ asciiAlphanum ; break ; case self :: ASCII_NONALPHANUM : $ subset = self :: $ asciNonAlphanum ; break ; default : $ subset = array_merge ( self :: $ asciiAlphanum , self :: $ asciNonAlphanum ) ; } $ count = count ( $ subset ) - 1 ; $ r = '' ; for ( $ i = 0 ; $ i < $ length ; $ i ++ ) { $ r .= $ subset [ mt_rand ( 0 , $ count ) ] ; } return $ r ; }
Generates a string of random ASCII characters

@author Art <a.molcanovas@gmail.com>

@param int $length The length of the string
@param int $subset Which subset to use - see class' ASCII_* constants

@return string
@since  1.3
Generates a string of random ASCII characters