<?php
/*******************************************************************
Name    :function rand_str($keta,$type)
Action    :generate random string number $keta digits
      $type ==  all   or 0 or null    :mixed alphabet&numeric
      $type ==  ab    or 1        :alphabet
      $type ==  caps  or 2        :capital letter only
      $type ==  small or 3        :small letter only
      $type ==  num   or 4        :numeric only
Call    :makepw(int $digit str $keta)
Return    :(str)$random string
Revision:
    1.00  Initial
                     2007.08.19 Ver1.00 Genki wrote
                     http://www.genkikko.net/
********************************************************************/
function rand_str($keta,$type){
    if(!
$keta){
        
$keta 8;
    }
    
mt_srand((double)microtime()*1000000);
    if(
$type == "all" || !$type){
        
//alphabet and numeric mixed
        
for($i=0,$str=null;$i<$keta;){
            
$num=mt_rand(0x00,0x7A);
            if((
0x30<$num&&$num<0x39) || (0x41<$num&&$num<0x5A) || (0x61<$num&&$num<0x7A)){
                
$str.=chr($num);
                
$i++;
            }
        }
        return (
$str);
    }elseif(
$type == "ab" || $type == 1){
        for(
$i=0,$str=null;$i<$keta;){
            
$num=mt_rand(0x30,0x7A);
            if((
0x41<$num&&$num<0x5A) || (0x61<$num&&$num<0x7A)){
                
$str.=chr($num);
                
$i++;
            }
        }
        return (
$str);
    }elseif(
$type == "caps" || $type == 2){
        for(
$i=0,$str=null;$i<$keta;){
            
$num=mt_rand(0x41,0x5A);
            
$str.=chr($num);
            
$i++;
        }
        return (
$str);
    }elseif(
$type == "small" || $type == 3){
        for(
$i=0,$str=null;$i<$keta;$i++){
            
$num=mt_rand(0x61,0x7A);
            
$str.=chr($num);
        }
        return (
$str);
    }elseif(
$type == "num" || $type == 4){
        for(
$i=0,$str=null;$i<$keta;$i++){
            
$str.=mt_rand(0,9);
        }
        return (
$str);
    }else{
        return(
"error:bad type.");
    }
}
?>