摘要:獲取名字獲取名字字隨機個字只取姓只取名默認情況姓名調用類,隨機生成名字引入文件博文的偽隨機數與真隨機數詳解
隨機生成國人的名字
getXingList(); $this->getMingList(); } /* 獲取姓列表 */ private function getXingList() { $this->arrXing=array( "趙","錢","孫","李","周","吳","鄭","王","馮","陳","褚","衛","蔣", "沈","韓","楊","朱","秦","尤","許","何","呂","施","張","孔","曹","嚴","華","金","魏", "陶","姜","戚","謝","鄒","喻","柏","水","竇","章","云","蘇","潘","葛","奚","范","彭", "郎","魯","韋","昌","馬","苗","鳳","花","方","任","袁","柳","鮑","史","唐","費","薛", "雷","賀","倪","湯","滕","殷","羅","畢","郝","安","常","傅","卞","齊","元","顧","孟", "平","黃","穆","蕭","尹","姚","邵","湛","汪","祁","毛","狄","米","伏","成","戴","談", "宋","茅","龐","熊","紀","舒","屈","項","祝","董","梁","杜","阮","藍","閔","季","賈", "路","婁","江","童","顏","郭","梅","盛","林","鐘","徐","邱","駱","高","夏","蔡","田", "樊","胡","凌","霍","虞","萬","支","柯","管","盧","莫","柯","房","裘","繆","解","應", "宗","丁","宣","鄧","單","杭","洪","包","諸","左","石","崔","吉","龔","程","嵇","邢", "裴","陸","榮","翁","荀","于","惠","甄","曲","封","儲","仲","伊","寧","仇","甘","武", "符","劉","景","詹","龍","葉","幸","司","黎","溥","印","懷","蒲","邰","從","索","賴", "卓","屠","池","喬","胥","聞","莘","黨","翟","譚","貢","勞","逄","姬","申","扶","堵", "冉","宰","雍","桑","壽","通","燕","浦","尚","農","溫","別","莊","晏","柴","瞿","閻", "連","習","容","向","古","易","廖","庾","終","步","都","耿","滿","弘","匡","國","文", "寇","廣","祿","闕","東","歐","利","師","鞏","聶","關","荊","司馬","上官","歐陽","夏侯", "諸葛","聞人","東方","赫連","皇甫","尉遲","公羊","澹臺","公冶","宗政","濮陽","淳于","單于", "太叔","申屠","公孫","仲孫","軒轅","令狐","徐離","宇文","長孫","慕容","司徒","司空"); $this->numbXing = count($this->arrXing); //姓總數 } /* 獲取名列表 */ private function getMingList() { $this->arrMing=array( "偉","剛","勇","毅","俊","峰","強","軍","平","保","東","文","輝","力","明","永","健","世","廣","志","義", "興","良","海","山","仁","波","寧","貴","福","生","龍","元","全","國","勝","學","祥","才","發","武","新", "利","清","飛","彬","富","順","信","子","杰","濤","昌","成","康","星","光","天","達","安","巖","中","茂", "進","林","有","堅","和","彪","博","誠","先","敬","震","振","壯","會","思","群","豪","心","邦","承","樂", "紹","功","松","善","厚","慶","磊","民","友","裕","河","哲","江","超","浩","亮","政","謙","亨","奇","固", "之","輪","翰","朗","伯","宏","言","若","鳴","朋","斌","梁","棟","維","啟","克","倫","翔","旭","鵬","澤", "晨","辰","士","以","建","家","致","樹","炎","德","行","時","泰","盛","雄","琛","鈞","冠","策","騰","楠", "榕","風","航","弘","秀","娟","英","華","慧","巧","美","娜","靜","淑","惠","珠","翠","雅","芝","玉","萍", "紅","娥","玲","芬","芳","燕","彩","春","菊","蘭","鳳","潔","梅","琳","素","云","蓮","真","環","雪","榮", "愛","妹","霞","香","月","鶯","媛","艷","瑞","凡","佳","嘉","瓊","勤","珍","貞","莉","桂","娣","葉","璧", "璐","婭","琦","晶","妍","茜","秋","珊","莎","錦","黛","青","倩","婷","姣","婉","嫻","瑾","穎","露","瑤", "怡","嬋","雁","蓓","紈","儀","荷","丹","蓉","眉","君","琴","蕊","薇","菁","夢","嵐","苑","婕","馨","瑗", "琰","韻","融","園","藝","詠","卿","聰","瀾","純","毓","悅","昭","冰","爽","琬","茗","羽","希","欣","飄", "育","瀅","馥","筠","柔","竹","靄","凝","曉","歡","霄","楓","蕓","菲","寒","伊","亞","宜","可","姬","舒", "影","荔","枝","麗","陽","妮","寶","貝","初","程","梵","罡","恒","鴻","樺","驊","劍","嬌","紀","寬","苛", "靈","瑪","媚","琪","晴","容","睿","爍","堂","唯","威","韋","雯","葦","萱","閱","彥","宇","雨","洋","忠", "宗","曼","紫","逸","賢","蝶","菡","綠","藍","兒","翠","煙","小","軒"); //名總數 $this->numbMing = count($this->arrMing); } // 獲取姓 private function getXing() { // mt_rand() 比rand()方法快四倍,而且生成的隨機數比rand()生成的偽隨機數無規律。 return $this->arrXing[mt_rand(0,$this->numbXing-1)]; } // 獲取名字 private function getMing() { return $this->arrMing[mt_rand(0,$this->numbMing-1)]; } // 獲取名字 public function getName($type=0) { $name = "" ; switch($type) { case 1: //2字 $name = $this->getXing().$this->getMing(); break; case 2: //隨機2、3個字 $name = $this->getXing().$this->getMing(); if(mt_rand(0,100)>50)$name .= $this->getMing(); break; case 3: //只取姓 $name = $this->getXing(); break; case 4: //只取名 $name = $this->getMing(); break; case 0: default: //默認情況 1姓+2名 $name = $this->getXing().$this->getMing().$this->getMing(); } return $name; } }
調用類,隨機生成名字:
getName(2); echo $name;
博文:
PHP的偽隨機數與真隨機數詳解
文章版權歸作者所有,未經允許請勿轉載,若此文章存在違規行為,您可以聯系管理員刪除。
轉載請注明本文地址:http://specialneedsforspecialkids.com/yun/21770.html
摘要:個人網站最近剛寫了一個手機在線播放的電影站使用日常手記更新使用的的查詢作用域的本地作用域去自定義可復用的約束集合,方便鏈式調用什么是本地查詢作用域本地作用域允許我們定義通用的約束集合以便在應用中復用。 關于作者 程序開發人員,不拘泥于語言與技術,目前主要從事PHP和前端開發,使用Laravel和VueJs,App端使用Apicloud混合式開發。合適和夠用是最完美的追求。 個人網站:...
摘要:如果我們給出了構造方法,系統將不再提供默認的無參構造方法。概念方便在沒有創建對象的情況下來進行調用方法變量。因為它的成員全部是靜態的所以私有了構造方法獲取隨機數的方法返回帶正號的值,該值大于等于 1.構造方法Constructor概述和格式(掌握) A:構造方法概述和作用 給對象的數據(屬性)進行初始化 B:構造方法格式特點 a:方法名與類名相同(大小寫也要與類名一致) b:...
摘要:自定義類的概述自定義類的概述代碼映射成現實事物的過程就是定義類的過程。自定義類的格式自定義類的格式使用類的形式對現實中的事物進行描述。 01引用數據類型_類 * A: 數據類型 * a: java中的數據類型分為:基本類型和引用類型 * B: 引用類型的分類 * a: Java為我們提供好的類,比如說:Scanner,Random等。 * b: 我們自己創建的類...
摘要:與工廠模式相比,建造者模式一般用來創建更為復雜的對象,因為對象的創建過程更為復雜,因此將對象的創建過程獨立出來組成一個新的類導演類。 什么是建造者設計模式 建造者模式:將一個復雜對象的構造與它的表示分離,使同樣的構建過程可以創建不同的表示的設計模式。 設計場景: 有一個用戶的UserInfo類,創建這個類,需要創建用戶的姓名,年齡,愛好等信息,才能獲得用戶具體的信息結果。如: 這是一個...
摘要:并把最終的隨機數輸出到控制臺。方法,在集合中如何存儲元素取決于方法的返回值返回,集合中只有一個元素。創建集合對象,傳入比較器。 1_HashSet存儲字符串并遍歷 A:Set集合概述及特點 通過API查看即可 B:案例演示 HashSet存儲字符串并遍歷 import java.util.HashSet; public class Demo1_HashSet { p...
閱讀 3228·2021-11-11 16:55
閱讀 2477·2021-10-13 09:39
閱讀 2408·2021-09-13 10:27
閱讀 2162·2019-08-30 15:55
閱讀 3086·2019-08-30 15:54
閱讀 3132·2019-08-29 16:34
閱讀 1827·2019-08-29 12:41
閱讀 1071·2019-08-29 11:33