Skip to content

Instantly share code, notes, and snippets.

@galvao
Created June 2, 2011 19:08
Show Gist options
  • Save galvao/1005069 to your computer and use it in GitHub Desktop.
Save galvao/1005069 to your computer and use it in GitHub Desktop.
Random string generation
<?php
/**
* Generates a random string based on ASCII coding.
* @author Er Galvão Abbott <galvao@galvao.eti.br>
* @see http://www.asciitable.com/
*/
$result = '';
$bgn = 33;
$end = 126;
$len = 32;
for ($c = 0; $c < $len; $c++) {
$chr = chr(mt_rand($bgn, $end));
$result .= $chr;
}
echo "$result\n";
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment