Jump to content

[SOLVED] quick question :D


adv

Recommended Posts

hello i have this function to generate random letters and numbers with any length that u want

 


<?php

function randomPassword($length =  {
   // all the chars we want to use
   $all = explode( " ",
         "a b c d e f g h i j k l m n o p q r s t u v w x y z "
         . "A B C D E F G H I J K L M N O P Q R S T U V W X Y Z "
         . "0 1 2 3 4 5 6 7 8 9 _");
    for($i=0;$i<$length;$i++) {
      srand((double)microtime()*1000000);
      $randy = rand(0, 61);
      $pass .= $all[$randy];
    }

     return $pass;
}

echo $new_filename = randomPassword(15);

?> 

i didnt make this myself i found it from google

but the thing that i dont understand  is here

 

$pass .= $all[$randy];  

 

why does it need to concatentate ??

i tried without the "." but it will show only one random letter or number

how is the concatentate operator makes such a big difference ::|

any oppion is good :D

thanks

 

Link to comment
Share on other sites

Unless you're using a really old version of php, there's no need to seed the random number generator for rand or shuffle or any of the other randomize type functions.

 

function randomPassword($length =  {
   $charlist = array_merge(range('a','z'), range('A','Z'), range(0,9), '_');
   shuffle($charlist);
   return implode('', array_slice($charlist, 0, $length));
} // end randomPassword

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.