生成n位不同的验证码
来源:互联网 发布:java工程师证书 编辑:程序博客网 时间:2024/05/24 05:07
方法一: 算法
1 //生成随机数函数中从strchar 数组中随机抽取
2 //字母区分大小写
3 //参数n为生成随机数的位数,一般取四位
4 public string RandomNum(int n) //
5 {
6 string strchar = "0,1,2,3,4,5,6,7,8,9" ;
7 string[] VcArray = strchar.Split(',') ;
8 string VNum = "" ;//由于字符串很短,就不用StringBuilder了
9 int temp = -1 ; //记录上次随机数值,尽量避免产生几个一样的随
10
11 机数
12 //采用一个简单的算法以保证生成随机数的不同
13 Random rand =new Random();
14 for ( int i = 1 ; i < n+1 ; i++ )
15 {
16 if ( temp != -1)
17 {
18 rand =new Random(i*temp*unchecked((int)
19
20 DateTime.Now.Ticks));
21 }
22 //int t = rand.Next(35) ;
23 int t=rand.Next(10);
24 if (temp != -1 && temp == t)
25 {
26 return RndNum( n);
27 }
28 temp = t ;
29 VNum += VcArray[t];
30 }
31 return VNum ;//返回生成的随机数
32 }
33 生成随机数后,将值赋值给一个Label控件,然后改一下Label背景的颜色,OK了
34
35
2 //字母区分大小写
3 //参数n为生成随机数的位数,一般取四位
4 public string RandomNum(int n) //
5 {
6 string strchar = "0,1,2,3,4,5,6,7,8,9" ;
7 string[] VcArray = strchar.Split(',') ;
8 string VNum = "" ;//由于字符串很短,就不用StringBuilder了
9 int temp = -1 ; //记录上次随机数值,尽量避免产生几个一样的随
10
11 机数
12 //采用一个简单的算法以保证生成随机数的不同
13 Random rand =new Random();
14 for ( int i = 1 ; i < n+1 ; i++ )
15 {
16 if ( temp != -1)
17 {
18 rand =new Random(i*temp*unchecked((int)
19
20 DateTime.Now.Ticks));
21 }
22 //int t = rand.Next(35) ;
23 int t=rand.Next(10);
24 if (temp != -1 && temp == t)
25 {
26 return RndNum( n);
27 }
28 temp = t ;
29 VNum += VcArray[t];
30 }
31 return VNum ;//返回生成的随机数
32 }
33 生成随机数后,将值赋值给一个Label控件,然后改一下Label背景的颜色,OK了
34
35
方法二: ASP.NET 2.0 HttpHandler实现生成图片验证码(示例代码下载)
http://blog.csdn.net/ChengKing/archive/2007/01/05/1475140.aspx
Trackback: http://tb.blog.csdn.net/TrackBack.aspx?PostId=496615
- 生成n位不同的验证码
- 生成n位不同的验证码
- 生成n位不同的验证码
- 生成n位不同的验证码
- ASP.NET生成n位不同的验证码
- ASP.NET生成n位不同的验证码
- ASP.NET生成n位不同的验证码
- ASP.NET生成n位不同的验证码
- ASP.NET生成n位不同的验证码
- ASP.NET生成n位不同的验证码
- ASP.NET生成n位不同的验证码
- ASP.NET生成N位不同的验证码技术
- 随机生成N位验证码的函数
- 用C#生成n条不重复的n位验证码
- 随机验证码生成(生成一个含有n位随机数字的字符串)
- Python(4)-- 随机生成N位验证码的字符
- 4位验证码的生成代码
- 4位随机验证码的生成
- Control Study -> 当鼠标在图片上移动时,放大图像区域
- ADO.Net都有哪些从数据库获取数据的方式
- 遍历目录和文件信息
- asp.net生成曲线图的过程
- 用 winmm 播放音乐
- 生成n位不同的验证码
- Collection -> 由IComparer派生的自定义比较器
- 当DataSet中包含主/子表时,Update更新步骤
- 什么是爱情?这就是爱情
- 自定义带结构的可序列化数据集DataSet.
- Asp.Net中Cache操作类
- 有效的Java异常
- 自定义数据库物理表中各列字段的名称
- java.lang.OutOfMemoryError: Java heap space 解决方法