Advertisement
SergioRP

Name Generator

May 9th, 2013
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.60 KB | None | 0 0
  1. <?php
  2. function makeName() {
  3.     $v = array('a', 'e', 'i', 'o', 'u'); #Vogais
  4.     $c = array('qu', 'w', 'r', 't', 'y', 'p', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', 'z', 'x', 'c', 'v', 'b', 'n', 'm', 'ch', 'tr'); #Consoantes
  5.     $nl = rand(4, 7); #Name length
  6.     $nxt = rand(1, 2); //1 = Vogal; 2 = Consoante
  7.     $str = '';
  8.  
  9.     for ($i=0;$i<=$nl;$i++) {
  10.         switch($nxt) {
  11.             case 1:
  12.                 $now = $v; #Vai escolher uma vogal
  13.                 break;
  14.             case 2:
  15.                 $now = $c; #Vai escolher uma consoante
  16.                 break;
  17.         }
  18.         $str = $str.$now[rand(0, count($now) - 1)];
  19.         $nxt = ($nxt == 1 ? 2 : 1);
  20.     }
  21.     return ucfirst($str);
  22. }
  23. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement