PHP生成随机单词
class GenRandWords
{ private static $_alphas = [
'a', 'b', 'c', 'd', 'e', 'f', 'g',
'h', 'i', 'j', 'k', 'l', 'm', 'n',
'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
]; // 生成
private $_num = 1; // 单词最小长度
private $_minLength = 5; // 单词最大长度
private $_maxLength = 20; public function __construct($config = [])
{
if (isset($config['num']) && $config['num'] > 0) {
$this->_num = $config['num'];
} if (isset($config['minLength']) && $config['minLength'] > 0) {
$this->_minLength = $config['minLength'];
} if (isset($config['maxLength']) && $config['maxLength'] > 0) {
$this->_maxLength = $config['maxLength'];
}
} public function generate()
{
$words = [];
$num = $this->_num; while ($num--) {
$words[] = $this->_genOneWord();
} return $words;
} private function _genOneWord()
{
$word = ''; $wordLength = mt_rand($this->_minLength, $this->_maxLength); while ($wordLength--) {
$index = mt_rand(0, 25);
$word .= self::$_alphas[$index];
} return $word;
}
}
用法:
$config = [
'num' => 100,
]; $genRandWords = new GenRandWords($config); $words = $genRandWords->generate();
PHP生成随机单词的更多相关文章
- 生成随机id对比
生成随机id 最近公司的项目游戏生成的随机不重复id,重复概率有点大, 代码如下: private static int id = 0; public static int serverID = 0; ...
- Java生成随机验证码
package com.tg.snail.core.util; import java.awt.Color; import java.awt.Font; import java.awt.Graphic ...
- C# 写的一个生成随机汉语名字的小程序
最近因为要做数据库相关的测试,频繁使用到测试数据,手动添加太过于麻烦,而且复用性太差,因此干脆花了点时间写了一个生成随机姓名和相关数据的类,贴在这里,有需用的同志们可以参考一下.代码本身质量不好,也不 ...
- [源码]RandomId 生成随机字符串
/* * 名称:RandomId * 功能:生成随机ID * 作者:冰麟轻武 * 日期:2012年1月31日 03:36:28 * 版本:1.0 * 最后更新:2012年1月31日 03:36:28 ...
- .net生成随机字符串
生成随机字符串的工具类: /// <summary> /// 随机字符串工具类 /// </summary> public class RandomTools { /// &l ...
- C#生成随机验证码
使用YZMHelper帮助类即可 using System; using System.Web; using System.Drawing; using System.Security.Cryptog ...
- loadrunner生成随机身份证和银行卡号
生成银行卡号码: Action() { char card[19] = {'6','2','2','7','0','0','0','0','0','0','0','0','0','0','0','0' ...
- PHP 生成随机字符串与唯一字符串
说明:生成随机字符串用到的方法有 mt_rand() 生成唯一字符串用到的方法有 md5(),uniqid(),microtime() 代码: <?php /* * 生成随机字符串 * @par ...
- RandomUser – 生成随机用户 JSON 数据的 API
RandomUser 是一个 API,它为您提供了一个或者一批随机生成的用户.这些用户可以在 Web 应用程序原型中用作占位符,将节省您创建自己的占位符信息的时间.您可以使用 AJAX 或其他方法来调 ...
随机推荐
- nexus 3.17.0 简单说明
nexus 在6.24 发布了3.17.0 ,同时包含了好多新的特性 以下为一些主要变动: routing rules 可以增强repo 的安全 apt repo 格式的支持 可以方便的为ubuntu ...
- 【luoguP2371】 [国家集训队]墨墨的等式
题目链接 考虑将所有的\(a_1x_1+a_2x_2+--+a_nx_n=B\)对\(a_1\)取模,那么所有可达到的B就分为了\(0\)~\(a_1-1\)类 如果对\(a_1\)取模为\(k\)的 ...
- 【洛谷P5019】铺设道路
题目链接 众所周知,这道题和积木大赛是同一道题 题意就是给出一段自然数序列,每次操作\((L,R)\)把区间\([L,R]\)的数全部减一,不允许出现负数,问把序列变为零的最小操作次数 贪心做法 样例 ...
- 微信小程序轮播组件
在index.wxml中添加以下代码 <view> <swiper indicator-dots="{{indicatorDots}}" autoplay=&qu ...
- JAVA学习网站分享
好久没用博客园了 最近工作不忙了,可以花时间自己学习知识提升自己,所以开始查找各种资料 java资源查找网站: http://www.java1234.com/ 前端学习网站: ...
- Spark安装(standalone)
文档:http://spark.apache.org/docs/latest/spark-standalone.html 安装scalahttps://www.scala-lang.org/downl ...
- Deep Reinforcement Learning with Iterative Shift for Visual Tracking
Deep Reinforcement Learning with Iterative Shift for Visual Tracking 2019-07-30 14:55:31 Paper: http ...
- unittest中的TestLoader使用
一:unittest中的TestLoader使用说明 第一步:unittest增加TestSuit() suite=unittest.TestSuite() 第二步:unittest增加Testloa ...
- array_slice
array_slice 分割数组, 效果相当于 substr 类似字符串操作
- eclipse :代码自动补全不生效解决办法
参考文章:https://blog.csdn.net/qq_35033270/article/details/79285821 请见下图! 恢复缺省值即可!