Generating random text

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • pitchke
    New Member
    • Sep 2007
    • 7

    Generating random text

    hey guys....
    i need php to generate random text...
    thanks in advance...
    tarun.
  • brettl
    New Member
    • Sep 2007
    • 41

    #2
    I've used these two function before to generate random passwords. I'm not sure if this is what you're looking for but it may put you in the right direction.

    [CODE=php]
    <?php
    function Random_Text($le ngth) {
    srand(date("s") );
    $possible_chara ctors = "abcdefghijklmn opqrstuvwxyz123 4567890ABCDEFGH IJKLMNOPQRSTUVW XYZ";
    $string = "";
    while(strlen($s tring)<$length) {
    $string .= substr($possibl e_charactors, rand()%(strlen( $possible_chara ctors)),1);
    }
    return($string) ;
    }

    echo 'random text: ';
    echo Random_Text(8);
    echo '<br/>';

    function ramdomword($len gth){

    srand((double)m icrotime()*1000 000);

    $vowels = array("a", "e", "i", "o", "u");
    $cons = array("b", "c", "d", "g", "h", "j", "k", "l", "m", "n", "p", "r", "s", "t", "u", "v", "w", "tr",
    "cr", "br", "fr", "th", "dr", "ch", "ph", "wr", "st", "sp", "sw", "pr", "sl", "cl");

    $num_vowels = count($vowels);
    $num_cons = count($cons);

    for($i = 0; $i < $length; $i++){
    $password .= $cons[rand(0, $num_cons - 1)] . $vowels[rand(0, $num_vowels - 1)];
    }

    return substr($passwor d, 0, $length);
    }

    echo '<br/>';
    echo 'random word(almost): ';
    echo ramdomword(10);
    ?>
    [/CODE]

    Comment

    • pbmods
      Recognized Expert Expert
      • Apr 2007
      • 5821

      #3
      Changed thread title to better describe the problem (did you know that threads whose titles contain phrases such as, 'urgent' actually get FEWER responses?).

      Comment

      Working...