<?php
namespace framework\src\cmd;
use framework\cao as cao;
final class random extends cao {
static protected function _autoincrement_( $length = 0, $int = false, $position = false ){
if( !empty($int) ){
$hash = "012345678901234567890123456789";
}else{
$data = '';
$uniqid = uniqid("",TRUE);
if( !empty($_SERVER['REQUEST_TIME']) ) $data .= $_SERVER['REQUEST_TIME'] if( !empty($_SERVER['HTTP_USER_AGENT']) ) $data .= $_SERVER['HTTP_USER_AGENT'] if( !empty($_SERVER['REQUEST_URI']) ) $data .= $_SERVER['REQUEST_URI'] if( !empty($_SERVER['REMOTE_ADDR']) ) $data .= $_SERVER['REMOTE_ADDR'] $hash = hash('ripemd128', $uniqid.md5($data) );
}
$data = '';
if( !empty($length) ){
for( $i = 0; $i < $length; $i ++ ){
$data .= mb_substr($hash, mt_rand(0, mb_strlen($hash) - 1), 1);
}
}
$microtime = str_replace(".", "", microtime(true));
if( empty($position) ){
$data = $data.$microtime;
}else{
$data = $microtime.$data;
}
return $data;
}
static protected function _ymdhis_( $length = 15 ){
if( !is_numeric( $length ) ){
$length = 15;
}
$data = date('YmdHis') $length_strlen = $length - mb_strlen($data);
if( $length_strlen === 0 ){
return $data;
}
if( $length_strlen < 0 ){
$data = mb_substr($data, 0, $length_strlen );
}
if( $length_strlen > 0 ){
$data .= substr(str_shuffle("012345678901234567890123456789"), 0, $length_strlen);
}
return $data;
}
static protected function _string_( $length = 0, $str = '' ){
$chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.$str;
$data = '';
if( !empty($length) ){
for( $i=0;$i<$length;$i++ ){
$data .= mb_substr($chars, mt_rand(0, mb_strlen($chars) - 1), 1);
}
}
return $data;
}
static protected function _number_( $length = 0 ){
if( empty($length) ){
return $length;
}
return substr(str_shuffle("012345678901234567890123456789"), 0, $length);
}
static protected function _uuid_( $length = 0, $space = '-' ){
$data = '';
if(!empty($_SERVER['REQUEST_TIME'])) $data.=$_SERVER['REQUEST_TIME'] if(!empty($_SERVER['HTTP_USER_AGENT'])) $data.=$_SERVER['HTTP_USER_AGENT'] if(!empty($_SERVER['REMOTE_PORT'])) $data.=$_SERVER['REMOTE_PORT'] if( !empty($_SERVER['REMOTE_ADDR']) ) $data .= $_SERVER['REMOTE_ADDR'] $hash = hash('ripemd128', uniqid("", TRUE).md5($data) );
$id = '';
if( !empty($space) ){
$id = substr($hash,0,8).$space.substr($hash,8,4).$space.substr($hash,12,4).$space.substr($hash,16,4).$space.substr($hash,20,12);
}else{
$id = $hash;
}
return $id;
}
}
?>