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. android 开发中fragment 遇到的问题

    http://yifeng.studio/2016/12/15/android-fragment-attentions/ 1.不要轻易在 fragment中引用 getactivity(); 解决方案 ...

  2. kmod编译找不到函数kmod_log

    编译报错: /usr/bin/ld: Warning: gc-sections option ignored libkmod/.libs/libkmod-util.a(libkmod-util.o): ...

  3. hypermesh2flac3d

    hypermesh2ansys2flac3d 目的: 将hypermesh中划分的网格输出到flac3d中.过程是hypermesh12.0-ansys13.0-flac3d3.0. 视频教程详见:h ...

  4. AngularJs的UI组件ui-Bootstrap分享(十二)——Rating

    Rating是一个用于打分或排名的控件.看一个最简单的例子: <!DOCTYPE html> <html ng-app="ui.bootstrap.demo" x ...

  5. Linux网络编程(多人在线聊天系统)

    一.首先是服务器的建立 首先是一个信号终止程序,发信号ctrl+c终止程序,而是是初始化网络通信. 创建一个描述符负责绑定服务器和监听服务器接收客户端的消息. socket()->sockadd ...

  6. 第二章 JavaScript语法·

    javascript代码放置位置: 1.将代码放置在文档<head>标签中的<script>标签之间: 2.将代码存为一个扩展名为.js的独立文件.典型做法是在文档的<h ...

  7. ueditor 图片上传功能(.net)

    假如下载的net文件 所在工程引用bin文件中的Newtonsoft.Json.dll 在浏览器中运行 `net/controller.ashx`,如果返回 "`{"state&q ...

  8. JavaScript测试题

    您的回答: 1.我们可以在下列哪个 HTML 元素中放置 Javascript 代码? 您的回答:<script> 2.写 "Hello World" 的正确 Java ...

  9. Android 数据库管理— — —更新数据

    <?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android=" ...

  10. C++网络编程之select

    select函数决定一个或者多个套接字(socket)的状态,如果需要的话,等待执行异步I/O. int select( __in        int    nfds, __inout    fd_ ...