How can i generate a random pin about 8 alphanumeric pins..?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • xavierDOTph
    New Member
    • Feb 2012
    • 6

    How can i generate a random pin about 8 alphanumeric pins..?

    i dont know how to generate pins..that will be inserted on the registration page ..that if the registration was pass it will be put on the field of `pins`.. thanks in advance ..
  • PsychoCoder
    Recognized Expert Contributor
    • Jul 2010
    • 465

    #2
    One way is a simple function that takes the length you want and the acceptable characters, something like this

    Code:
    function GenerateRandom($length, $charset='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789')
    {
        $randString = '';
        $count = strlen($charset);
        while ($length--) 
    	{
            $randString .= $charset[mt_rand(0, $count-1)];
        }
        return $randString;
    }
    Hope that helps

    Comment

    Working...