How can I generate random words in PHP?

php generate random dictionary word
php random string
php random number
how to generate unique random number in php
php generate random string of characters
php generate random alphanumeric string
php generate random string fixed length
random name generator in php

How I can get random words without repeating in PHP? Help

If you don't want to type the alphabet manually, you can do the folowing:

function getRandomWord($len = 10) {
    $word = array_merge(range('a', 'z'), range('A', 'Z'));
    return substr(implode($word), 0, $len);

codepad example

If this is a database id, i suggest you the folowing:

function createUniqueId() {
    while (1) {
       $word = getRandomWord();
       if (!idExists($word)) { // idExists returns true if the id is already used
           return $word;

How can I generate random words in PHP?, If you don't want to type the alphabet manually, you can do the folowing: <?php function getRandomWord($len = 10) { $word  As you can see, generating random and unique hexadecimal strings up to 40 characters long is very easy in PHP. Generate Cryptographically Secure Random Strings. The three functions to generate random alphanumeric strings that we have discussed so far are not cryptographically secure.

Try this func

function randw($length=4){
        return substr(str_shuffle("qwertyuiopasdfghjklzxcvbnm"),0,$length);

str_shuffle - Manual, str_shuffle — Randomly shuffles a string shuffle() - Shuffle an array; rand() - Generate a random integer return $word{0} . str_shuffle(substr($word, 1, -1)) . Generate Random Numbers In PHP Programs Source Code Before sharing source code, I want to say about this program. Basically, this program is created using the PHP rand (min,max); function. The rand () function generates a random integer (know more about PHP rand).

$words = preg_split('//', 'abcdefghijklmnopqrstuvwxyz0123456789', -1);
foreach($words as $word) {
    echo $word . '<br />';

How can I generate random words in PHP? : PHPhelp, If I get you right (you have a list of words and you want to print them randomly, each word only once), you want to get the size of array, use rand() function to get a  The rand() function generates a random integer. Tip: If you want a random integer between 10 and 100 (inclusive), use rand (10,100). Tip: The mt_rand() function produces a better random value, and is 4 times faster than rand(). Syntax

function getrandomstring($length) {

       global $template;
       settype($template, "string");

       $template = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
       /* this line can include numbers or not */

       settype($length, "integer");
       settype($rndstring, "string");
       settype($a, "integer");
       settype($b, "integer");

       for ($a = 0; $a <= $length; $a++) {
               $b = rand(0, strlen($template) - 1);
               $rndstring .= $template[$b];

       return $rndstring; 

PHP: Human-readable Random String · GitHub, @param string $length Desired length of random string. *. * retuen string Random string. */. function readable_random_string($length = 6). {. $string = '';. A word generator finds random words from multiple languages with the letters and the length you choose. You can specify what letters you want words in the randomly generated list and the type of words you want to find i.e., noun, verb, adjective. A word unscrambler unscrambles letters you already know. Here are a few uses for a Word Maker

$letters  = array ( "a" ,"b" ,"c" ,"d" ,"e" ,"f" ,"g" ,"h" ,"i" ,"j" ,
                    "k" ,"l" ,"m" ,"n" ,"o" ,"p" ,"q" ,"r" ,"s" ,"t" ,
                    "u" ,"v" ,"w" ,"x" ,"y" ,"z" );

function letterfNum($letterNumber ,$resoltNumber){
    global $letters;
        for ($i = 0 ; $i < $resoltNumber ;$i++){
            $lettersTotal = "";
            $rand = array_rand($letters,$letterNumber);
            foreach($rand as $key => $letterIndex){ 
                foreach($letters as $orginalIndex => $orginalValue){
                    if ($letterIndex == $orginalIndex){
                        $lettersTotal .= $orginalValue;
        echo $lettersTotal."<br>";  


Generate Random Alphanumeric Strings in PHP, Generating Random Numbers in PHP In other words, you might get the same random number twice, but that does not mean that the  Generate a random, unique, alpha-numeric string using PHP. Examples: EA070 aBX32gTf APPROACH 1: Brute Force The first approach is the simplest one to understand and thus brute force. It can be achieved as follows: Store all the possible letters into a string. Generate random index from 0 to string length-1. Print the letter at that index.

Get random word from English dictionary in PHP, How To Generate Random Password In PHP? Get visitors country and city in PHP using Freegeoip API. After that, we use PHP rand() function to get the random  Right now the randomizer generates a list of 6 random words by default but you can change that to generate a word list of anywhere from two to ten words. For band names and business projects, I find that setting the random word chooser to pick three or four words gives you an optimal list to work with.

PHP rand() Function, PHP Version: 4+. PHP Changelog: PHP 7.1: The rand() function is an alias of mt_rand(). PHP 4.2.0: The random number generator is seeded automatically. random-word. This is a simple python package to generate random english words. If you need help after reading the below, please find me at @vaibhavsingh97 on Twitter.. If you love the package, please :star2: the repo.

How to select a random word from array in php, This is a simple built-in function in PHP. array_rand - Manual You can get more How would I generate unique random strings based on input number PHP? You can also play the game Catchphrase by turning the tool into a random catchphrase word generator. Go to the games drop-down menu and choose "Catchphrase" as the option. This will change the random words to a random Catchphrase word list allowing you to play Catchphrase as much as you like.

  • Could you maybe give us an example of what you're looking for? What is a "random word"? Is it a random collection of letters? Or do you want dictionary words? If the latter, you need to have a word list. To avoid repeating, you should store the words you've already produced (probably using a hashtable) and avoid printing the same one twice.
  • Could you tell me 1 to 9 and a to z random words but with out repeating? Thanks.
  • @ABC: What do you mean by "without repeating"? aabc is not allowed, or abc1, abc1 is not allowed?
  • deleted (obviously it's too late for me doze)
  • Sorry for my unproficient English. I mean, I have to need min 1 to max 6 words with 0 to 9 and a to z but I don't need old words again. Thanks
  • Code only answers are discouraged. Consider adding at least a tiny bit of explanation.
  • @ABC Girl - That will shuffle the array of words, and print them out one by one, so no, no repeating.
  • If the array can have double values add $words = array_unique($words); before the shuffle()
  • Thanks, but I need random words with 0 to 9 and a to z keywords for my ID table. So, I don't need repeat.
  • @ABC Girl - something like that? I'm having trouble understanding what you mean...
  • Is without repeat? I mean, I have use this random keywords in database table ID. So, I don't need repeat keywords. Thanks
  • Isn't it too costly?