@@ -35,6 +35,18 @@ public static function randomFloat($min = -999999999, $max = 999999999, $dmin =
3535 return floatval ($ intNum . '. ' . $ rand . $ floatEnd );
3636 }
3737
38+ /**
39+ * 获取随机的时间
40+ * @param string $format PHP的时间日期格式化字符
41+ * @return false|string
42+ * @author zhaoxiang <zhaoxiang051405@gmail.com>
43+ */
44+ public static function randomDate ($ format = 'Y-m-d H:i:s ' ) {
45+ $ timestamp = time () - mt_rand (0 , 86400 * 3650 );
46+
47+ return date ($ format , $ timestamp );
48+ }
49+
3850 /**
3951 * 构建随机IP地址
4052 * @return string
@@ -85,7 +97,7 @@ public static function randomProtocol() {
8597 }
8698
8799 /**
88- *
100+ * 随机生成一个顶级域名
89101 * @author zhaoxiang <zhaoxiang051405@gmail','com>
90102 */
91103 public static function randomTld () {
@@ -104,4 +116,41 @@ public static function randomTld() {
104116 return $ tldArr [0 ];
105117 }
106118
119+ /**
120+ * 获取一个随机的域名
121+ * @return string
122+ * @author zhaoxiang <zhaoxiang051405@gmail.com>
123+ */
124+ public static function randomDomain () {
125+ $ len = mt_rand (6 , 16 );
126+
127+ return strtolower (Strs::randString ($ len )) . '. ' . self ::randomTld ();
128+ }
129+
130+ /**
131+ * 随机生成一个URL
132+ * @param string $protocol 协议名称,可以不用指定
133+ * @return string
134+ * @author zhaoxiang <zhaoxiang051405@gmail.com>
135+ */
136+ public static function randomUrl ($ protocol = '' ) {
137+ $ protocol = $ protocol ? $ protocol : self ::randomProtocol ();
138+
139+ return $ protocol . ':// ' . self ::randomDomain ();
140+ }
141+
142+ /**
143+ * 随机生成一个邮箱地址
144+ * @param string $domain 可以指定邮箱域名
145+ * @return string
146+ * @author zhaoxiang <zhaoxiang051405@gmail.com>
147+ */
148+ public static function randomEmail ($ domain = '' ) {
149+ $ len = mt_rand (6 , 16 );
150+ $ domain = $ domain ? $ domain : self ::randomDomain ();
151+
152+ return Strs::randString ($ len ) . '@ ' . $ domain ;
153+
154+ }
155+
107156}
0 commit comments