会员
周边
新闻
博问
闪存
赞助商
Chat2DB
所有博客
当前博客
我的博客
我的园子
账号设置
会员中心
简洁模式
...
退出登录
注册
登录
sqlite例子
博客园
首页
新随笔
联系
订阅
管理
关于随机数C#一例
关于随机数C#一例 ------------------------------------ public class CommonClass { //生成随机数函数 public static string GetRandomInt_StrLen3() { //产生随机数3位 int sTmp = GetRandomInt(3); string index = GetNormalStrLenN(sTmp, 3); return index; } public static string GetRandomInt_StrLen5() { //产生随机数5位 int sTmp = GetRandomInt(5); string index = GetNormalStrLenN(sTmp, 5); return index; } public static string GetRandomInt_StrLenN(int N) { //产生随机数N位 int sTmp = GetRandomInt(N); string index = GetNormalStrLenN(sTmp, N); return index; } public static int GetRandomInt(int intLength) { //产生随机数N位 int MaxVal = 9; if (intLength <= 0) intLength = 1; string mv = ""; for (int i = 0; i < intLength; i++) { mv += "9"; } MaxVal = TInt(mv); int sTmp = GetRandomInt(0, MaxVal); return sTmp; } public static int GetRandomInt(int MinValue,int MaxValue) { Random rdm1 = new Random(unchecked((int)DateTime.Now.Ticks)); int sTmp = rdm1.Next(MinValue, MaxValue); return sTmp; } public static string GetNormalStrLenN(int RandomInt,int N) { string sTmp = RandomInt.ToString(); string temp = ""; if (sTmp.Length < N) { //小于N位时前面补0的个数 如12->00012 for (int i = 0; i < N - sTmp.Length; i++) { temp = temp + "0"; } } string index = temp + sTmp; return index; } // } /// <summary> /// 地块编号工厂 /// </summary> public static class DkbhFactory { /// <summary> /// 创建一个新的地块编号 规划调整地块 /// </summary> public static string CreateNewDkbh_Ghjbtz(string xzqhdm) { string currentdatetime = System.DateTime.Now.ToString("yyyyMMddHHmmss"); //获取随机数index string index = "0001"; //产生随机数5位 index = GetRandomInt_StrLen5(); string tmpdkbh = xzqhdm + currentdatetime + index; return tmpdkbh; } /// <summary> /// 创建一个新的地块编号 规划实施建设用地项目地块 如:51011220091125103900001 /// </summary> public static string CreateNewDkbh_Jsydxmdk(string xzqhdm) { string currentdatetime = System.DateTime.Now.ToString("yyyyMMddHHmmss"); //获取随机数index string index = "0001"; //产生随机数5位 index = GetRandomInt_StrLen5(); string tmpdkbh = xzqhdm + currentdatetime + index; return tmpdkbh; } /// <summary> /// 创建一个新的办文编号 规划实施建设用地项目地块 如:T01-20091125103800001 /// </summary> /// <returns></returns> public static string CreateNewProjectID_Jsydxmdk() { string currentdatetime = System.DateTime.Now.ToString("yyyyMMddHHmmss"); //获取随机数index string index = "0001"; //产生随机数5位 index = GetRandomInt_StrLen5(); string tmpdkbh = "T01-" + currentdatetime + index; return tmpdkbh; } public static string GetRandomInt_StrLen5() { //产生随机数5位 string index = CommonClass.GetRandomInt_StrLen5(); return index; } }
posted @
2011-10-10 14:15
sqlite例子
阅读(
260
) 评论(
0
)
收藏
举报
刷新页面
返回顶部
公告