asp.net 随机生成数字串 5
stringDateInfo=DateTime.Now.ToString("yyyyMMddHHmmssfff");我用这句获取的是当前时间我想获取成我想要的格式比如20...
string DateInfo = DateTime.Now.ToString("yyyyMMddHHmmssfff");
我用这句获取的是当前时间 我想获取成我想要的 格式 比如 201362****_0
****是随机生成的四位数字 该怎么调用啊? 展开
我用这句获取的是当前时间 我想获取成我想要的 格式 比如 201362****_0
****是随机生成的四位数字 该怎么调用啊? 展开
3个回答
展开全部
public static string YZM()
{
string[] rander = {"p","0","1","2","3","4","5","6","7","8","9","a","s","d","f","g","h","j","k","l","q","w","e","r","t","y","u","i","o","z","x","v","c","b","n","m","Q","W","E","R","T","Y","U","I","O","P","A","S","D","F","G","H","J","K","L","Z","X","C","V","B","N","M"};
int sub;
string yzm = "";
Random rand = new Random();
rand = new Random(345 * unchecked((int)DateTime.Now.Second));
for (int i = 0; i < 4; i++)
{
sub = rand.Next(61);
yzm += rander[sub];
}
return yzm;
}
纯数字还是要字母,纯数字,把那个数组改一下就行了,然后把你前边的字串拼接就行了
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Random r=new Random();
stringDateInfo=DateTime.Now.ToString("yyyyMd")+r.Next(1000-10000).ToString()+"_0"
大致是这样,我没有运行,你稍微修改一下就可以了
stringDateInfo=DateTime.Now.ToString("yyyyMd")+r.Next(1000-10000).ToString()+"_0"
大致是这样,我没有运行,你稍微修改一下就可以了
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
使用随机数生成一个4位的数字就可以了,再在前面加上你的日期。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询