c#生成不重复的字符串
来源:互联网 发布:java面试项目经历 编辑:程序博客网 时间:2024/06/04 00:40
using System;namespace DotNet.Utilities{ public class RandomOperate { // 一:随机生成不重复数字字符串 private int rep = 0; public string GenerateCheckCodeNum(int codeCount) { string str = string.Empty; long num2 = DateTime.Now.Ticks + this.rep; this.rep++; Random random = new Random(((int)(((ulong)num2) & 0xffffffffL)) | ((int)(num2 >> this.rep))); for (int i = 0; i < codeCount; i++) { int num = random.Next(); str = str + ((char)(0x30 + ((ushort)(num % 10)))).ToString(); } return str; } //方法二:随机生成字符串(数字和字母混和) public string GenerateCheckCode(int codeCount) { string str = string.Empty; long num2 = DateTime.Now.Ticks + this.rep; this.rep++; Random random = new Random(((int)(((ulong)num2) & 0xffffffffL)) | ((int)(num2 >> this.rep))); for (int i = 0; i < codeCount; i++) { char ch; int num = random.Next(); if ((num % 2) == 0) { ch = (char)(0x30 + ((ushort)(num % 10))); } else { ch = (char)(0x41 + ((ushort)(num % 0x1a))); } str = str + ch.ToString(); } return str; } #region /// <summary> /// 从字符串里随机得到,规定个数的字符串. /// </summary> /// <param name="allChar"></param> /// <param name="CodeCount"></param> /// <returns></returns> private string GetRandomCode(string allChar, int CodeCount) { //string allChar = "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"; string[] allCharArray = allChar.Split(','); string RandomCode = ""; int temp = -1; Random rand = new Random(); for (int i = 0; i < CodeCount; i++) { if (temp != -1) { rand = new Random(temp * i * ((int)DateTime.Now.Ticks)); } int t = rand.Next(allCharArray.Length - 1); while (temp == t) { t = rand.Next(allCharArray.Length - 1); } temp = t; RandomCode += allCharArray[t]; } return RandomCode; } #endregion }}
0 0
- c#生成不重复的字符串
- [组合算法] 生成不重复的字符串
- 用C#生成不重复的随机数
- C#生成不重复的随机数
- 使用c#生成不重复的随机数
- 用C#生成不重复的随机数
- 用C#生成不重复的随机数
- 用C#生成不重复的随机数
- C#生成100%不重复的随机数
- 用C#生成不重复的随机数
- 用C#生成不重复的随机数
- c#生成不重复随机数的方法
- C#下生成不重复的随机数
- 用C#生成不重复的随机数
- 用C#生成不重复的随机数
- C#生成不重复随机数的方法
- C#随机生成不重复的数值
- C# 生成不重复的随机数
- PAT 1005 继续(3n+1)猜想
- Linux使用PAM锁定多次登陆失败的用户(含重置错误次数)
- android:windowSoftInputMode属性详解
- Nginx 关于 Rewrite 执行顺序详解
- jboss4.2.3更改端口和默认根应用程序
- c#生成不重复的字符串
- CCControlExtension/CCControlButton
- [C++ GUI Programming with Qt 4/5 代码] && [从Qt4过渡至Qt5(The Transition from Qt 4.x to Qt 5)]
- CCControlExtension/CCControl
- 关于随便长浮点数相加的小程序
- unicode与多字节的字符串转换
- JSP工作原理
- 【js设计模式笔记---观察者模式】
- Android手机通过电脑上网的几种方法