Generate a random alphabetic word
Many times we need to create a random word in variable length . Then it seems complex to us cos php’s Rand() function return only random numbers not alphabatic charecter . And after getting a post at phpResource i have discovered a simple function for this problem . here is the code .
——————————-
function rand_word($length)
{
$word = “”;
for($ix = 1; $ix <= $length; $ix++)
{
$word .= chr(rand(97, 122));
}
return($word);
}
————————-
All you need to call this function with the desired langth . Its soo simplee……..
Example : rand_word(5);
July 9th, 2006 at 6:04 pm
I hope i would be even grab the random number at any length . What u think?
July 9th, 2006 at 6:21 pm
Yeh using this function you can get any combination of charecter at any length . You just have to set the start and end limit of ASCII charecter number .
Here is the ASCII charecter chart sheet : http://www.csgnetwork.com/asciiset.html
July 10th, 2006 at 8:37 pm
Thank U for this work
July 11th, 2006 at 3:59 pm
What about the concept of random word based on the current time? In this case, you wont experience any duplicate random word.
Anyway, you did good work. Go ahead.
Rupom
http://www.rupom.info