各位好
碰到个问题 想不到法子 所以来这里取经 嘿嘿~~
我需要做一个随便数 要是10数字的 用int 类型接收 说是长度不够
声明成long 型的 那个随便方法 next() 参数又不支持 long型 Random ran = new Random();
string code = (ran.Next(begin, end)).ToString();begin和end 都是int型的 因为数据的字段是int型的 在不动数据库字段类型的情况下 如何解决 这个问题呢?
各位路过的朋友 有没有 碰到过类似的问题 还请指教一二~先行谢过了呵~~
解决方案 »
- 急,急!FileUpload1控件点击浏览文件后,我想用image显示所浏览的图片,在触发提交事件之前显示,怎么实现?谢谢,感激不尽!
- 自己写的一个类
- DropDownList捆绑分类无法显示的错误,高手请教
- asp.net级联菜单问题
- ASP.NET复杂表头
- 怎样实现这个:点击网页链接,打开客户端程序?急救!!!
- webservice的客户端调用问题?
- 返回上一页并刷新
- Pls help me!! about the smtp email! thanks!
- 如何在ASP.NET中获取服务器/客户端的时间?特急?请各位大虾帮帮忙...
- 求助:asp.net 后台调用jQuery函数
- ASP.NET上传图片并显示问题
string a = new Random().Next(9999, 99999).ToString();
string b = new Random().Next(9999, 99999).ToString();
return a+b;
using System.Collections.Generic;
using System.Text;
namespace NetCMS.Common
{
public class Rand
{
/// <summary>
/// 生成随机数字
/// </summary>
/// <param name="length">生成长度</param>
/// <returns></returns>
public static string Number(int Length)
{
return Number(Length, false);
}
/// <summary>
/// 生成随机数字
/// </summary>
/// <param name="Length">生成长度</param>
/// <param name="Sleep">是否要在生成前将当前线程阻止以避免重复</param>
/// <returns></returns>
public static string Number(int Length,bool Sleep)
{
if(Sleep)
System.Threading.Thread.Sleep(3);
string result = "";
System.Random random = new Random();
for (int i = 0; i < Length; i++)
{
result += random.Next(10).ToString();
}
return result;
}
/// <summary>
/// 生成随机字母与数字
/// </summary>
/// <param name="IntStr">生成长度</param>
/// <returns></returns>
public static string Str(int Length)
{
return Str(Length, false);
}
/// <summary>
/// 生成随机字母与数字
/// </summary>
/// <param name="Length">生成长度</param>
/// <param name="Sleep">是否要在生成前将当前线程阻止以避免重复</param>
/// <returns></returns>
public static string Str(int Length, bool Sleep)
{
if(Sleep)
System.Threading.Thread.Sleep(3);
char[] Pattern = new char[] { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C',
'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z' };
string result = "";
int n = Pattern.Length;
System.Random random = new Random(~unchecked((int)DateTime.Now.Ticks));
for (int i = 0; i < Length; i++)
{
int rnd = random.Next(0,n);
result += Pattern[rnd];
}
return result;
}
/// <summary>
/// 生成随机纯字母随机数
/// </summary>
/// <param name="IntStr">生成长度</param>
/// <returns></returns>
public static string Str_char(int Length)
{
return Str_char(Length, false);
}
/// <summary>
/// 生成随机纯字母随机数
/// </summary>
/// <param name="Length">生成长度</param>
/// <param name="Sleep">是否要在生成前将当前线程阻止以避免重复</param>
/// <returns></returns>
public static string Str_char(int Length, bool Sleep)
{
if (Sleep)
System.Threading.Thread.Sleep(3);
char[] Pattern = new char[] { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N',
'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z' };
string result = "";
int n = Pattern.Length;
System.Random random = new Random(~unchecked((int)DateTime.Now.Ticks));
for (int i = 0; i < Length; i++)
{
int rnd = random.Next(0, n);
result += Pattern[rnd];
}
return result;
}
}
}