最新下载
热门教程
- 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;
}
相关文章
- 二重螺旋玛尔洁如何配卡 10-30
- dnf手游刃影技能怎么连招-刃影技能连招技巧 10-30
- 三国望神州虎牢关之战怎么通关 10-30
- 王者万象棋乔汐如何玩 10-30
- 二重螺旋梦魇残声怎么打 10-30
- 三国群英传策定九州公孙瓒有哪些玩法技巧 10-30