'.', 'prob' => 0.07, 'ender' => true), array('char' => ',', 'prob' => 0.10, 'ender' => false), array('char' => '!', 'prob' => 0.03, 'ender' => true), array('char' => '?', 'prob' => 0.03, 'ender' => true)); header("Content-Type: text/plain"); function gen($len) { global $punct, $dict; $ret = ''; $capital = true; while ($len) { $word = $dict[mt_rand(0, count($dict) - 1)]; if ($capital) $word = strtoupper($word[0]) . substr($word, 1); else $word = strtolower($word); $end_selector = mt_rand() / mt_getrandmax(); $valid = false; $ind = -1; while (true) { for ($i = 0; $i < count($punct); $i++) { $end_selector -= $punct[$i]['prob']; if ($end_selector < 0) { $ind = $i; break; } } if (($len > 1) || (($ind != -1) && $punct[$ind]['ender'])) break; } if ($ind == -1) { $ret .= $word . ' '; $capital = false; } else { $capital = $punct[$ind]['ender']; $ret .= $word . $punct[$ind]['char'] . ' '; } $len--; } return $ret; } if (!$_REQUEST['length']) echo 'length isn\'t set. go ahead and add it in the address bar, like this:' . "\n" . 'http://..../pokeloremipsum.php?length=40'; else if ($_REQUEST['length'] > 1000) echo 'sorry, maximum 1000 words'; else if ($_REQUEST['length'] < 0) echo 'length can\'t be negative, doofus'; else echo gen((int)$_REQUEST['length']);