Note Submitter: RichardBronosky (1st at last dot com)
----
I like the idea of expertphp at y!, but the implementation was too expensive for my load. Here is the tightest solution to generating $x random [[:alnum:]] chars that I could think of. I use this for creating random file names.
<?php
// Assuming $z is "_file_prefix_" or an empty string.
// If $z is unset an E_NOTICE will be added to your logs.
// That's bad for production boxes!
for($x=0;$x<32;$x++){
$y = rand(0,61);
$z .= chr( $y + (($y<10) ? 48 : (($y<36) ? 55 : 61)) );
}
echo $z;
?>
To get an array, just change this line:
<?php
// $z can be unset, null, or an existing array. E_ERROR if it's a string.
$z[] = chr( $y + (($y<10) ? 48 : (($y<36) ? 55 : 61)) );
?>
lmpx.com only provides a reader for public news (NNTP) servers. It is not
affiliated with the servers or forums shown here and is not responsible for
the content of articles, which is written by their respective authors.