亚洲免费乱码视频,日韩 欧美 国产 动漫 一区,97在线观看免费视频播国产,中文字幕亚洲图片

      1. <legend id="ppnor"></legend>

      2. 
        
        <sup id="ppnor"><input id="ppnor"></input></sup>
        <s id="ppnor"></s>

        php生成隨機(jī)數(shù)的三種方法

        字號:


            如何用php生成1-10之間的不重復(fù)隨機(jī)數(shù)?
            例1,使用shuffle函數(shù)生成隨機(jī)數(shù)。
            1<?php
            2$arr=range(1,10);
            3shuffle($arr);
            4foreach($arr as $values)
            5{
            6 echo $values." ";
            7}
            8?>
            例2,使用array_unique函數(shù)生成隨機(jī)數(shù)。
            1<?php
            2$arr=array();
            3while(count($arr)<10)
            4{
            5 $arr[]=rand(1,10);
            6 $arr=array_unique($arr);
            7}
            8echo implode(" ",$arr);
            9?>
            例3,使用array_flip函數(shù)生成隨機(jī)數(shù),可以去掉重復(fù)值。
            01<?php
            02$arr=array();
            03$count1=0;
            04$count = 0;
            05$return = array();
            06while ($count < 10)
            07 {
            08 $return[] = mt_rand(1, 10);
            09 $return = array_flip(array_flip($return));
            10 $count = count($return);
            11 } //www.jbxue.com
            12foreach($return as $value)
            13 {
            14 echo $value." ";
            15 }
            16echo "<br/>";
            17$arr=array_values($return);// 獲得數(shù)組的值
            18foreach($arr as $key)
            19echo $key." ";
            20?>
            php隨機(jī)數(shù)生成函數(shù)示例
            01<?php
            02function randpw($len=8,$format='ALL'){
            03$is_abc = $is_numer = 0;
            04$password = $tmp ='';
            05switch($format){
            06case 'ALL':
            07$chars='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
            08break;
            09case 'CHAR':
            10$chars='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
            11break;
            12case 'NUMBER':
            13$chars='0123456789';
            14break;
            15default :
            16$chars='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
            17break;
            18} // www.jbxue.com
            19mt_srand((double)microtime()*1000000*getmypid());
            20while(strlen($password)<$len){
            21$tmp =substr($chars,(mt_rand()%strlen($chars)),1);
            22if(($is_numer <> 1 && is_numeric($tmp) && $tmp > 0 )|| $format == 'CHAR'){
            23$is_numer = 1;
            24}
            25if(($is_abc <> 1 && preg_match('/[a-zA-Z]/',$tmp)) || $format == 'NUMBER'){
            26$is_abc = 1;
            27}
            28$password.= $tmp;
            29}
            30if($is_numer <> 1 || $is_abc <> 1 || empty($password) ){
            31$password = randpw($len,$format);
            32}
            33return $password;
            34}
            35for($i = 0 ; $i < 10; $i++){
            36echo randpw(8,'NUMBER');
            37echo "<br>";
            38}