rt,生成12位的随机数,
for (int i = 0; i < Convert.ToInt32(ddlCount.SelectedValue); i++)
{
CardInfo card3 = new CardInfo();
card3.AreaId = ddlArea.SelectedItem.Value;
card3.CardId = card3.AreaId + ReturnMaxCardId();
card3.CardPwd = ??//获得随机密码
card3.CurrentNumber = 0
card3.Int1 = long.Parse(ReturnMaxCardId());
card3.Int2 = 0;
card3.IsPay = 0;
card3.MacId = "";
card3.ParValue = ddlPayValue.SelectedValue;
card3.State = 0;
card3.Str1 = "";
card3.Str2 = "";
card3.UseDate = DateTime.Parse("2000-1-1");
card3.UserId = 0;
CardInfoManager.AddCardInfo(card3);
}
密码是在循环中 随机 生成的!!!
当前操作中不重复即可!大家给个思路啊!
不知道我这篇文章是否对你有帮助
http://www.cnblogs.com/eaglet/archive/2011/01/17/1937083.html
生成12位的随机数和生成12个1位的随机数并没有区别呀
况且Random 的NextDouble 方法本身就可以生成精度15到16位的随机数,你去掉前面的0.不就可以了么
你是想传10就生成10位的密码?那你循环生成不就行了?
Guid.NewGuid().ToString("N").Substring(0, 12);
private const string RANDOM_RANGE = "1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ";
public static string RandomString(int maxSize)
{Random rand = new Random(Environment.TickCount);StringBuilder sb = new StringBuilder(maxSize);
for (int i = 0; i < maxSize; i++)
{sb.Append(RANDOM_RANGE[rand.Next(RANDOM_RANGE.Length + 1)]);
}
return sb.ToString();
}
你说的是这样的么?那个随机字符串你可以添加你还想生成的字符,如小写,其他特殊字符也可以;
/// <summary>
/// 数字随机数
/// </summary>
/// <param name="n">生成长度</param>
/// <returns></returns>
public static string RandNum(int n)
{
char[] arrChar = new char[] { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' };
StringBuilder num = new StringBuilder();
Random rnd = new Random(DateTime.Now.Millisecond);
for (int i = 0; i < n; i++)
{
num.Append(arrChar[rnd.Next(0, 9)].ToString());
}
return num.ToString();
}
一个随机数这么复杂?随机一个数字,然后执行12遍。再连起来不就ok了!
System.Random rand = new Random();
int len = rand.Next(4, 5);
char[] chars = "0123456789".ToCharArray();
System.Text.StringBuilder myStr = new System.Text.StringBuilder();
for (int iCount = 0; iCount < len; iCount++)
{
myStr.Append(chars[rand.Next(chars.Length)]);
}
string text = myStr.ToString();