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);


5 Responses to “Generate a random alphabetic word”

  1. Micheal Paul Says:

    I hope i would be even grab the random number at any length . What u think?

  2. Khademul Islam (Shimul) Says:

    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

  3. Aiman Says:

    Thank U for this work

  4. MA Razzaque Rupom Says:

    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

  5. Florian Says:

    Hi,
    I found your blog via google by accident and have to admit that youve a really interesting blog :-)
    Just saved your feed in my reader, have a nice day :)

Leave a Reply