//<summary>
///得到随机字符.
///</summary>
///<param name="intLength">Length of the int.</param>
///<param name="booNumber">if set to <c>true</c> [boo number].</param>
///<param name="booSign">if set to <c>true</c> [boo sign].</param>
///<param name="booSmallword">if set to <c>true</c> [boo smallword].</param>
///<param name="booBigword">if set to <c>true</c> [boo bigword].</param>
///<returns></returns>

public string getRandomizer(int intLength, bool booNumber, bool booSign, bool booSmallword, bool booBigword)
{
//定义
Random ranA = new Random();
int intResultRound = 0;
int intA = 0;
string strB = "";
while (intResultRound < intLength)
{
//生成随机数A,表示生成类型
//1=数字,2=符号,3=小写字母,4=大写字母
intA = ranA.Next(1, 5);
//如果随机数A=1,则运行生成数字
//生成随机数A,范围在0-10
//把随机数A,转成字符
//生成完,位数+1,字符串累加,结束本次循环
if (intA == 1 && booNumber)
{
intA = ranA.Next(0, 10);
strB = intA.ToString() + strB;
intResultRound = intResultRound + 1;
continue;
}
//如果随机数A=2,则运行生成符号
//生成随机数A,表示生成值域
//1:33-47值域,2:58-64值域,3:91-96值域,4:123-126值域
if (intA == 2 && booSign == true)
{
intA = ranA.Next(1, 5);
//如果A=1
//生成随机数A,33-47的Ascii码
//把随机数A,转成字符
//生成完,位数+1,字符串累加,结束本次循环
if (intA == 1)
{
intA = ranA.Next(33, 48);
strB = ((char)intA).ToString() + strB;
intResultRound = intResultRound + 1;
continue;
}

//如果A=2
//生成随机数A,58-64的Ascii码
//把随机数A,转成字符
//生成完,位数+1,字符串累加,结束本次循环
if (intA == 2)
{
intA = ranA.Next(58, 65);
strB = ((char)intA).ToString() + strB;
intResultRound = intResultRound + 1;
continue;
}

//如果A=3
//生成随机数A,91-96的Ascii码
//把随机数A,转成字符
//生成完,位数+1,字符串累加,结束本次循环
if (intA == 3)
{
intA = ranA.Next(91, 97);
strB = ((char)intA).ToString() + strB;
intResultRound = intResultRound + 1;
continue;
}

//如果A=4
//生成随机数A,123-126的Ascii码
//把随机数A,转成字符
//生成完,位数+1,字符串累加,结束本次循环
if (intA == 4)
{
intA = ranA.Next(123, 127);
strB = ((char)intA).ToString() + strB;
intResultRound = intResultRound + 1;
continue;
}
}

//如果随机数A=3,则运行生成小写字母
//生成随机数A,范围在97-122
//把随机数A,转成字符
//生成完,位数+1,字符串累加,结束本次循环
if (intA == 3 && booSmallword == true)
{
intA = ranA.Next(97, 123);
strB = ((char)intA).ToString() + strB;
intResultRound = intResultRound + 1;
continue;
}

//如果随机数A=4,则运行生成大写字母
//生成随机数A,范围在65-90
//把随机数A,转成字符
//生成完,位数+1,字符串累加,结束本次循环
if (intA == 4 && booBigword == true)
{
intA = ranA.Next(65, 89);
strB = ((char)intA).ToString() + strB;
intResultRound = intResultRound + 1;
continue;
}
}
return strB;
}

C#生成随机字符串的更多相关文章

  1. .net生成随机字符串

    生成随机字符串的工具类: /// <summary> /// 随机字符串工具类 /// </summary> public class RandomTools { /// &l ...

  2. PHP 生成随机字符串与唯一字符串

    说明:生成随机字符串用到的方法有 mt_rand() 生成唯一字符串用到的方法有 md5(),uniqid(),microtime() 代码: <?php /* * 生成随机字符串 * @par ...

  3. PHP生成随机字符串包括大小写字母

    PHP生成随机字符串包括大小写字母,这里介绍两种方法: 第一种:利用字符串函数操作 <?php /** *@blog <www.phpddt.com> */ function cre ...

  4. 生成随机字符串(UUID方法)

    这是另一种用UUID生成随机字符串的方法. public class RandomGenerator{ private int length; public void setLength(int le ...

  5. SQL生成随机字符串

    1.SQLserve生成随机字符串 SELECT replace(newid(), '-', '')

  6. php生成随机字符串可指定纯数字、纯字母或者混合的

    php 生成随机字符串 可以指定是纯数字 还是纯字母 或者混合的. 可以指定长度的. function rand_zifu($what,$number){ $string=''; for($i = 1 ...

  7. JS生成随机字符串的多种方法

    这篇文章主要介绍了JS生成随机字符串的方法,需要的朋友可以参考下 下面的一段代码,整理电脑时,记录备查. <script language="javascript"> ...

  8. PHP生成随机字符串与唯一字符串

    代码如下: <?php /* * 生成随机字符串 * @param int $length 生成随机字符串的长度 * @param string $char 组成随机字符串的字符串 * @ret ...

  9. php 生成随机字符串,数字,大写字母,小写字母,特殊字符可以随意组合

    * 生成随机字符串* @param int       $length  要生成的随机字符串长度* @param string    $type    随机码类型:0,数字+大小写字母:1,数字:2, ...

  10. PHP中生成随机字符串,数字+大小写字母随机组合

    简单的生成随机字符串: /* * 生成随机字符串 * * $length 字符串长度 */ function random_str($length) { // 密码字符集,可任意添加你需要的字符 $c ...

随机推荐

  1. oc语言复制视频文件

    void copyFile() { NSString *home=NSHomeDirectory(); NSString *path=[NSString stringWithFormat:@" ...

  2. Android(java)学习笔记64:线程的控制

    1. 线程休眠: Java中线程休眠指让正在运行的线程暂停执行一段时间,进入阻塞状态,通过调用Thread类的静态方法sleep得以实现. 当线程调用sleep进入阻塞状态后,在其休眠的时间内,该线程 ...

  3. Android adb not responsing

    netstat -aon | findstr "5037" and you will find the process "kadb.exe" that used ...

  4. 算法java(Robert Sedgewick)基本API-StdOut.java

    /************************************************************************* * Compilation: javac StdO ...

  5. Differential Geometry之第三章曲面的局部理论

    第三章.曲面的局部理论 1.曲面的概念 1.1.曲面的概念 1.2.切平面与法向 2.曲面的第一基本形式 3.曲面的第二基本形式 正定矩阵:一个n阶的实对称矩阵M是正定的的条件是当且仅当对于所有的非零 ...

  6. latex之设置字体大小

    \tiny\scriptsize\footnotesize\small\normalsize\large\Large\LARGE\huge\Huge

  7. html+css--水平居中总结-不定宽块状元素方法(三)

    来源:http://www.imooc.com/code/6365 除了前两节讲到的插入table标签,以及改变元素的display类型,可以使不定宽块状元素水平居中之外,本节介绍第3种实现这种效果的 ...

  8. OpenFlow概述

    OpenFlow名称里面虽然包括“Flow”,但其并不是“又一个流程引擎”,我们认为世界上的流程引擎已经足够多了,每个流程引擎都各有千秋,有的甚至免费,所以我们不需要再做一个流程引擎,我们做OpenF ...

  9. JAVA IO流的简单总结+收集日志异常信息

    1.字节流: IuputStream 所有字节输出流的超类 . 抽象类 ---- FileInputStream ---- BufferedInputStream:提供数据的读取效率,拓展方法(内部维 ...

  10. 学习Slim Framework for PHP v3 (四)--get()是怎么加进去的?

    看看官网加粗的一句话: At its core, Slim is a dispatcher that receives an HTTP request, invokes an appropriate ...