<?php

/**
* Returns a random string of length $len consisting of A-Z 0-9.
* The first character will always be an alphabet.
*
* Requires srand()
*/
function RandStr($len=8)
{
	$s = '';
	for ($i=0; $i < $len; $i++) {
		if ($i == 0) $r = rand()%26;
		else $r = rand()%36;
		if ($r >= 26) $s .= chr($r + ord('0')-26);
		else $s.= chr($r+ord('A'));
	}
	return $s;
}


/* *
 *  Function : string rand_pass()
 *
 *  Purpose : Returns a random but pronounceable password.
 *  Note: You may edit the $num_letters and $array variables
 *
 *  Author: Sebastien Cevey <seb@cine7.net>
 *  Project: Web OpenScripts <http://wos.sourceforge.net>
 * */

function rand_pass() {

  # Pronounceable pieces of words
  $array = array(
		 "ap","baz","car","dus","tin","rog","sti","rev","pik","sty","lev","qot","rel","vid",
		 "kro","xo","pro","wia","axi","jer","foh","mu","ya","zol","gu","pli","cra",
		 "den","bi","sat","ry","qui","wip","fla","gro","tav","peh","gil","lot",
		 "kal","zan","noc","bat","tev","lun","pal","hom","cun","wos","vox"
		 );

 
  # Minimum number of letters
  $num_letters = 6;
  
  # Maximum number of letters
  $max_letters = 10;
  
  # Fraction of uppercased letters (randomized too...)
  $uppercased = 0;

  # Randomize on microseconds
  mt_srand ((double)microtime()*1000000);

  # Create random pass (too long for the moment)
  for($i=0; $i<$num_letters; $i++)
    $pass .= $array[mt_rand(0, (count($array) - 1))];
	
	print "$pass ";
  # Make sure there is not twice the same letter one after the other
  for($i=1; $i<strlen($pass); $i++) {
    if(substr($pass, $i, 1) == substr($pass, $i-1, 1))
      $pass = substr($pass, 0, $i) . substr($pass, $i+1);
  }

  # Randomize the pass case [for each letter]
  if ($uppercased)
  for($i=0; $i<strlen($pass); $i++) {
    if(mt_rand(0, $uppercased) == 0)
      $pass = substr($pass,0,$i) . strtoupper(substr($pass, $i,1)) . substr($pass, $i+1);
  }


  # Shorten it now
  $pass = substr($pass, 0, $num_letters+mt_rand(0,$max_letters - $num_letters));

  # Return the password
  return $pass;
}


?>