Tell me more ×
Programming Puzzles & Code Golf Stack Exchange is a question and answer site for programming puzzle enthusiasts and code golfers. It's 100% free, no registration required.

My problem is that I am using the random string creator shown below, I am not using 'alpha', I am using 'fourlet'. The only problem is that this in an array and that

substr($pool, mt_rand(0, strlen($pool) -1), 1);

doesn't work as a random creator for an array of data. Can anyone please help?

Below is the full code for the helper.

{
function random_string($type = 'alnum', $len = 8)
{
    switch($type)
    {
        case 'basic'    : return mt_rand();
            break;
        case 'alnum'    :
        case 'numeric'  :
        case 'nozero'   :
        case 'alpha'    :

                switch ($type)
                {
                    case 'alpha'    :   $pool = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
                        break;
                    case 'fourlet'  :   $pool = array('my', 'fun', 'zone', '12', '24', '37');
                        break;
                }

                $str = '';
                for ($i=0; $i < $len; $i++)
                {
                    $str .= substr($pool, mt_rand(0, strlen($pool) -1), 1);
                }
                return $str;
            break;
        case 'unique'   :
        case 'md5'      :

                    return md5(uniqid(mt_rand()));
            break;
        case 'encrypt'  :
        case 'sha1' :

                    $CI =& get_instance();
                    $CI->load->helper('security');

                    return do_hash(uniqid(mt_rand(), TRUE), 'sha1');
            break;
    }
}

}

So

share|improve this question
4  
This belongs on stackoverflow.com, not here. – Peter Taylor Jul 17 '12 at 6:53

closed as off topic by Peter Taylor, Gareth, w0lf, Howard, Prince John Wesley Jul 17 '12 at 8:50

Questions on Programming Puzzles & Code Golf Stack Exchange are expected to relate to programming puzzle or code golf within the scope defined in the FAQ. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about closed questions here.

Browse other questions tagged or ask your own question.