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
https://forums.phpfreaks.com/topic/137847-solved-quick-question-d/
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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.