Random string

December 5, 2008 by admin  
Filed under PHP

generates a random string from an array of characters

<?php
// function to generate random strings
function RandomString($length=32)
{
$randstr=”;
srand((double)microtime()*1000000);
//our array add all letters and numbers if you wish
$chars = array ( ‘a’,'b’,'c’,'d’,'e’,'f’);
for ($rand = 0; $rand <= $length; $rand++)
{
$random = rand(0, count($chars) -1);
$randstr .= $chars[$random];
}
return $randstr;
}
?>

and call it like this

<?php
echo RandomString(8);
?>

Related posts:

  1. Random XML feeds with PHP This example will display results from random XML feeds, note...
  2. random numbers This example shows how to produce random numbers in VB.net...
  3. dice game #include #include #include void main() { /*variables*/ int mydice1 ,mydice2...
  4. bubblesort routine # include # include void bubblesort(int array[],int size); void main()...
  5. Get stock quotes <?phpClass yahoo{function get_stock_quote($symbol){$url = sprintf(""http://finance.yahoo.com/d/quotes.csv?s=%s&f=sl1d1t1c1ohgv"" ,$symbol);$fp = fopen($url, ""r"");if(!fp){echo ""error...

Related posts brought to you by Yet Another Related Posts Plugin.

Speak Your Mind

Tell us what you're thinking...
and oh, if you want a pic to show with your comment, go get a gravatar!