using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks; namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
//int number;
//int count = 7;
//string checkCode = String.Empty; //存放随机码的字符串 //System.Random random = new Random(); //for (int i = 0; i < count; i++) //产生7位校验码
//{
// number = random.Next();
// number = number % 36;
// if (number < 10)
// {
// number += 48; //数字0-9编码在48-57
// }
// else
// {
// number += 55; //字母A-Z编码在65-90
// } // checkCode += ((char)number).ToString();
//}
//Console.WriteLine(checkCode);
Program p = new Program();
bool booNumber = true;
bool booSign = true;
bool booSmallword = true;
bool booBigword = true;
//p.getRandomizer(7, booNumber, booSign, booSmallword, booBigword);
Console.WriteLine(p.getRandomizer(, booNumber, booSign, booSmallword, booBigword));
Console.ReadLine();
}
public string getRandomizer(int intLength, bool booNumber, bool booSign, bool booSmallword, bool booBigword)
{
//定义
Random ranA = new Random();
int intResultRound = ;
int intA = ;
string strB = "";
while (intResultRound < intLength)
{
//生成随机数A,表示生成类型
//1=数字,2=符号,3=小写字母,4=大写字母
intA = ranA.Next(, );
//如果随机数A=1,则运行生成数字
//生成随机数A,范围在0-10
//把随机数A,转成字符
//生成完,位数+1,字符串累加,结束本次循环
if (intA == && booNumber)
{
intA = ranA.Next(, );
strB = intA.ToString() + strB;
intResultRound = intResultRound + ;
continue;
}
//如果随机数A=2,则运行生成符号
//生成随机数A,表示生成值域
//1:33-47值域,2:58-64值域,3:91-96值域,4:123-126值域
if (intA == && booSign == true)
{
intA = ranA.Next(, );
//如果A=1
//生成随机数A,33-47的Ascii码
//把随机数A,转成字符
//生成完,位数+1,字符串累加,结束本次循环
if (intA == )
{
intA = ranA.Next(, );
strB = ((char)intA).ToString() + strB;
intResultRound = intResultRound + ;
continue;
} //如果A=2
//生成随机数A,58-64的Ascii码
//把随机数A,转成字符
//生成完,位数+1,字符串累加,结束本次循环
if (intA == )
{
intA = ranA.Next(, );
strB = ((char)intA).ToString() + strB;
intResultRound = intResultRound + ;
continue;
} //如果A=3
//生成随机数A,91-96的Ascii码
//把随机数A,转成字符
//生成完,位数+1,字符串累加,结束本次循环
if (intA == )
{
intA = ranA.Next(, );
strB = ((char)intA).ToString() + strB;
intResultRound = intResultRound + ;
continue;
} //如果A=4
//生成随机数A,123-126的Ascii码
//把随机数A,转成字符
//生成完,位数+1,字符串累加,结束本次循环
if (intA == )
{
intA = ranA.Next(, );
strB = ((char)intA).ToString() + strB;
intResultRound = intResultRound + ;
continue;
}
} //如果随机数A=3,则运行生成小写字母
//生成随机数A,范围在97-122
//把随机数A,转成字符
//生成完,位数+1,字符串累加,结束本次循环
if (intA == && booSmallword == true)
{
intA = ranA.Next(, );
strB = ((char)intA).ToString() + strB;
intResultRound = intResultRound + ;
continue;
} //如果随机数A=4,则运行生成大写字母
//生成随机数A,范围在65-90
//把随机数A,转成字符
//生成完,位数+1,字符串累加,结束本次循环
if (intA == && booBigword == true)
{
intA = ranA.Next(, );
strB = ((char)intA).ToString() + strB;
intResultRound = intResultRound + ;
continue;
}
}
return strB;
}
}
}

C#生成随机字符串(数字,字母,特殊符号)的更多相关文章

  1. python 生成随机字符串

    1.生成随机字符串 #数字+字母+符号 def getRandChar(n): l = [] #sample = '0123456789abcdefghijklmnopqrstuvwxyz!@#$%^ ...

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

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

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

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

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

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

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

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

  6. C#生成随机字符串

    //<summary> ///得到随机字符. ///</summary> ///<param name="intLength">Length o ...

  7. .net生成随机字符串

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

  8. iOS开发:Swift/Objective-C高效生成随机字符串

    原文连接 Objective-C版 // 随机生成字符串(由大小写字母.数字组成) + (NSString *)random: (int)len { char ch[len]; for (int in ...

  9. 生成随机字符串 php

    /** +---------------------------------------------------------- * 生成随机字符串 +------------------------- ...

随机推荐

  1. Adobe Reader/Acrobat修改页面底色为豆沙绿

    Adobe Acrobat_Pro_8修改PDF页面底色为豆沙绿保护视力(同样适用于Adobe Reader) http://jingyan.baidu.com/article/9989c746189 ...

  2. python 面向对象编程学习

    1. 问题:将所有代码放入一个py文件:无法维护 方案:如果将代码才分放到多个py文件,好处: 1. 同一个名字的变量互相不影响 2.易于维护 3.引用模块: import module 2.包:解决 ...

  3. 转:js中this、call、apply的用法

    (一)关于this首先关于this我想说一句话,这句话记住了this的用法你也就差不多都能明白了:this指的是当前函数的对象.这句话可能比较绕,我会举出很多例子和这句话呼应的!(看下文)1.首先看下 ...

  4. 一个非常有意思的css3属性filter

    filter这属性貌似可以是img图片在黑白与彩色间转换 filter:grayscale(1)为黑白色,filter:grayscale(0)位彩色,可以用于hover效果 img:hover{fi ...

  5. offse

    关于offset共有5个东西需要弄清楚: 1.offsetParent 2.offsetTop 3.offsetLeft 4.offsetWidth 5.offsetHeight (1)offsetW ...

  6. UpdatePanel里的Repeater和DropDownList

    在updatepanel里使用dropdownlist的AutoPostBack,正常情况下都可以局部刷新. 但是,如果updatepanel下是Repeater,repeater里绑定dropdow ...

  7. IIS7+windows 64位配置注意事项

    问题和解决办法 1  如果网站为Asp:再asp中注意启用父路径 2  操作必须使用一个可更新的查询:给用户iis_iusrs 一个完全控制的权限 3  Windows(64位IIS)未在本地计算机上 ...

  8. Spring中的SPEL

    src\dayday\Person.java package dayday;/** * Created by I am master on 2016/11/28. */public class Per ...

  9. Android四大组件-Activity

    http://android.tgbus.com/Android/androidnews/201204/419485.shtml

  10. http://zh.lucida.me/

    一个很厉害的在美国Google的学长的博客