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. 今天第一节PS课

  2. Python开发入门与实战18-Windows Azure 虚拟机部署

    18. 微软云虚拟机部署 上一章节我们介绍了如何在新浪云部署我们的在python django应用,本章我们来介绍如何Windows Azure上部署我们的应用. 18.1. 注册Windows Az ...

  3. unity5.0材质添加问题

    将Material拖放到Cube的Inspector视图中 材质添加图片背景,unity自带了很多种材质类型点击Shader下拉按钮可以更换材质类型为Diffuse camera preview: G ...

  4. mvc 导入,导出excel

    最近主要做导入excel 在网上查询了代码 public FileResult DownLoadExcelJiZuChaXunGenRenXiaoFeiJiLu() { DataTable dt = ...

  5. 第一个structs+spring+hibernate的web程序

    1. 数据库: Column Type Comment id int(11) Auto Increment   name varchar(50) NULL   url varchar(255) NUL ...

  6. 7.2.3 使用RenderTargetBitmap类生成图片

    RenderTargetBitmap类可以将可视化对象转换为位图,也就是说它可以将任意的UIElement以位图的形式呈现.那么我们在实际的编程中通常会利用RenderTargetBitmap类来对U ...

  7. css width height

    css 中body 的默认宽度是100%,但是默认高度为0px

  8. NSOperationQueue的其他方法

    1.设置最大并发数 什么是并发数 同时执行的任务数 比如,同时开3个线程执行3个任务,并发数就是3   最大并发数的相关方法 - (NSInteger)maxConcurrentOperationCo ...

  9. BackTrack5-r3任务栏显示网络图标及自定义DNS

    任务栏显示网络连接图标:安装NM工具,在BT终端中执行:apt-get install network-manager按y继续执行,显示:ldconfig deferred processing no ...

  10. codeforces 734E(DFS,树的直径(最长路))

    题目链接:http://codeforces.com/contest/734/problem/E 题意:有一棵黑白树,每次操作可以使一个同色连通块变色,问最少几次操作能使树变成全黑或全白. 思路:先进 ...