您目前尚未登陆,请选择【登陆】或【注册
首页->全站代码->NETCMSv1.5(Build0509)完整源码版>>NetCMS.Common/Rand.cs>>代码在线查看
温馨提示:代码在线浏览功能只能做为源码浏览参考,不能展示项目的全部,如果想更进一步了解该代码请下载:NETCMSv1.5(Build0509)完整源码版


当前文件路径:NetCMSv15/NetCMS.Common/Rand.cs 文件类型
普通视图
		            
1//====================================================== 2//== (c)2008 aspxcms inc by NeTCMS v1.0 == 3//== Forum:bbs.aspxcms.com == 4//== Website:www.aspxcms.com == 5//====================================================== 6using System; 7using System.Collections.Generic; 8using System.Text; 9 10namespace NetCMS.Common 11{ 12 public class Rand 13 { 14 /// <summary> 15 /// 生成随机数字 16 /// </summary> 17 /// <param name="length">生成长度</param> 18 /// <returns></returns> 19 public static string Number(int Length) 20 { 21 return Number(Length, false); 22 } 23 24 /// <summary> 25 /// 生成随机数字 26 /// </summary> 27 /// <param name="Length">生成长度</param> 28 /// <param name="Sleep">是否要在生成前将当前线程阻止以避免重复</param> 29 /// <returns></returns> 30 public static string Number(int Length,bool Sleep) 31 { 32 if(Sleep) 33 System.Threading.Thread.Sleep(3); 34 string result = ""; 35 System.Random random = new Random(); 36 for (int i = 0; i < Length; i++) 37 { 38 result += random.Next(10).ToString(); 39 } 40 return result; 41 } 42 43 /// <summary> 44 /// 生成随机字母与数字 45 /// </summary> 46 /// <param name="IntStr">生成长度</param> 47 /// <returns></returns> 48 public static string Str(int Length) 49 { 50 return Str(Length, false); 51 } 52 /// <summary> 53 /// 生成随机字母与数字 54 /// </summary> 55 /// <param name="Length">生成长度</param> 56 /// <param name="Sleep">是否要在生成前将当前线程阻止以避免重复</param> 57 /// <returns></returns> 58 public static string Str(int Length, bool Sleep) 59 { 60 if(Sleep) 61 System.Threading.Thread.Sleep(3); 62 char[] Pattern = new char[] { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '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' }; 63 string result = ""; 64 int n = Pattern.Length; 65 System.Random random = new Random(~unchecked((int)DateTime.Now.Ticks)); 66 for (int i = 0; i < Length; i++) 67 { 68 int rnd = random.Next(0,n); 69 result += Pattern[rnd]; 70 } 71 return result; 72 } 73 74 75 /// <summary> 76 /// 生成随机纯字母随机数 77 /// </summary> 78 /// <param name="IntStr">生成长度</param> 79 /// <returns></returns> 80 public static string Str_char(int Length) 81 { 82 return Str_char(Length, false); 83 } 84 85 /// <summary> 86 /// 生成随机纯字母随机数 87 /// </summary> 88 /// <param name="Length">生成长度</param> 89 /// <param name="Sleep">是否要在生成前将当前线程阻止以避免重复</param> 90 /// <returns></returns> 91 public static string Str_char(int Length, bool Sleep) 92 { 93 if (Sleep) 94 System.Threading.Thread.Sleep(3); 95 char[] Pattern = new char[] { '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' }; 96 string result = ""; 97 int n = Pattern.Length; 98 System.Random random = new Random(~unchecked((int)DateTime.Now.Ticks)); 99 for (int i = 0; i < Length; i++) 100 { 101 int rnd = random.Next(0, n); 102 result += Pattern[rnd]; 103 } 104 return result; 105 } 106 } 107} 108
还没有找到您心仪的内容?请用.net源码大搜捕
代码片断 打包下载该项目完整源码:NETCMSv1.5(Build0509)完整源码版

- 企业客户管理系统源码

- 学习型留言板源码

- 漂亮许愿墙前台程序源码

- ExtenTree无限级树源码

- 酒店客房管理系统

- jquery无刷新分页、排序

- TreeView+XML实现的菜单

- 无限级树形菜单(Sql数据库)

51Aspx.com 版权所有 CopyRight © 2000-2008. 京ICP备06046876号