最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
asp.net中C#随机数组数据的例子
时间:2022-06-25 06:01:00 编辑:袖梨 来源:一聚教程网
随机数组数据、随机int数字、随机字符串代码
#region 随机业务 ////// 对该业务进行随机排序 // /// 08-10-24 /// /// ///private static List GetRandomSchemeList(List list) { List BuList = list; Maticsoft.Model.TB_Ap[] BuListtemp = new Maticsoft.Model.TB_Ap[list.Count]; int[] temp = GetRandomUnrepeatArray(0, BuList.Count - 1, BuList.Count); for (int i = 0; i < temp.Length; i++) { BuListtemp[i] = BuList[temp[i]]; } BuList.Clear(); BuList.AddRange(BuListtemp); return BuList; } /// /// 随机数 /// public static Random random = new Random(); ////// 随机不重复的Int 数值 /// /// /// /// ///public static int[] GetRandomUnrepeatArray(int minValue, int maxValue, int count) { //Random rnd = new Random(); int length = maxValue - minValue + 1; byte[] keys = new byte[length]; random.NextBytes(keys); int[] items = new int[length]; for (int i = 0; i < length; i++) { items[i] = i + minValue; } Array.Sort(keys, items); return items; } #endregion
例子2
private static int rep = 0; // /// 生成随机数字字符串 /// /// 待生成的位数 /// 生成的数字字符串 public static string GenerateCheckCodeNum(int codeCount) { string str = string.Empty; long num2 = DateTime.Now.Ticks + rep; rep++; Random random = new Random(((int)(((ulong)num2) & 0xffffffffL)) | ((int)(num2 >> rep))); for (int i = 0; i < codeCount; i++) { int num = random.Next(); str = str + ((char)(0x30 + ((ushort)(num % 10)))).ToString(); } return str; } /// 生成随机字母字符串(数字字母混和) /// /// 待生成的位数 /// 生成的字母字符串 public static string GenerateCheckCode(int codeCount) { string str = string.Empty; long num2 = DateTime.Now.Ticks + rep; rep++; Random random = new Random(((int)(((ulong)num2) & 0xffffffffL)) | ((int)(num2 >> 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; }
相关文章
- 人们熟悉的寄居蟹属于以下哪种分类 神奇海洋11月21日答案 11-21
- 第五人格11.22共研服有什么更新 11月22日共研服更新内容介绍 11-21
- 原神恰斯卡怎么培养 11-21
- 无期迷途四星装束是谁 11-21
- 王者荣耀帝丹高中校服怎么获得 11-21
- 光遇姆明季后续版本怎么玩 11-21