生成一个8位的随机字符串
function make_coupon_card() {
$code = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
$rand = $code[rand(0,25)]
.strtoupper(dechex(date('m')))
.date('d').substr(time(),-5)
.substr(microtime(),2,5)
.sprintf('%02d',rand(0,99));
for(
$a = md5( $rand, true ),
$s = '0123456789ABCDEFGHIJKLMNOPQRSTUV',
$d = '',
$f = 0;
$f < 8;
$g = ord( $a[ $f ] ),
$d .= $s[ ( $g ^ ord( $a[ $f + 8 ] ) ) - $g & 0x1F ],
$f++
);
return $d;
} 对于( $g ^ ord( $a[ $f + 8 ] ) ) - $g & 0x1F 的按位异或 减去本身 再进行的与运算,最终的范围是0-31之间,这个是如何确定的?
生成一个8位的随机字符串
function make_coupon_card() {
$code = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
$rand = $code[rand(0,25)]
.strtoupper(dechex(date('m')))
.date('d').substr(time(),-5)
.substr(microtime(),2,5)
.sprintf('%02d',rand(0,99));
for(
$a = md5( $rand, true ),
$s = '0123456789ABCDEFGHIJKLMNOPQRSTUV',
$d = '',
$f = 0;
$f < 8;
$g = ord( $a[ $f ] ),
$d .= $s[ ( $g ^ ord( $a[ $f + 8 ] ) ) - $g & 0x1F ],
$f++
);
return $d;
} 对于( $g ^ ord( $a[ $f + 8 ] ) ) - $g & 0x1F 的按位异或 减去本身 再进行的与运算,最终的范围是0-31之间,这个是如何确定的?
( $g ^ ord( $a[ $f + 8 ] ) ) - $g & 0x1F
简而言之有个关键点,运算符-的优先级要比&高。
所以整体来看应该是( ( $g ^ ord( $a[ $f + 8 ] ) ) - $g )和0x1F进行与运算,
而0x1F就是十进制的31,取与的结果范围就限定在了0 - 31之间。
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号