Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8243745
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T21:37:10+00:00 2026-06-07T21:37:10+00:00

My problem is that I am using the random string creator shown below, I

  • 0

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T21:37:11+00:00Added an answer on June 7, 2026 at 9:37 pm

    I have done some changes. Hope this will help you.

     <?php
    

    // $input = array(“Neo”, “Morpheus”, “Trinity”, “Cypher”, “Tank”);
    // $rand_keys = array_rand($input, 2);
    // echo $input[$rand_keys[0]] . “\n”;
    // echo $input[$rand_keys[1]] . “\n”;

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

        switch ($type)
        {
        case 'alpha'    :   $pool = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
            break;
        case 'fourlet'  :   $pool = array('my', 'fun', 'zone', '12', '24', '37');
            break;
        }
    
        $str = '';
            if(gettype($pool)=='string'){
                for ($i=0; $i < $len; $i++){
                    $str .= substr($pool, mt_rand(0, strlen($pool) -1), 1);
                }
            }   
            else if(gettype($pool)=='array'){       
                $rand_keys = array_rand($pool,4);
             $str=$pool[$rand_keys[0]].$pool[$rand_keys[1]].$pool[$rand_keys[2]].$pool[$rand_keys[3]];
    
            }       
    
    
        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;
    }
    

    }

    var_dump(random_string(‘fourlet’,8));

    ?>

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a JQuery (using JQuery 1.4.2) problem that exhibits only in IE8 in
I am reading a plist file using code below. My problem is that the
My root problem is that when using calls Dispose on a StreamWriter , it
My problem is that I am using the .hover method to get the x
I'm facing a problem that drives me crazy, I created a java application using
I'm facing a problem that seems to have no straighforward solution. I'm using java.util.Map
I'm using Entity Framework in my project, and I have the problem that, once
I am using swfupload to upload files on a website, the problem that every
I want to make a windowless application. The problem is that I'm using a
My problem actually is that I was using the response body before the callback

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.