Asp.net生成随机不重复的函数(方法)
// 生成三位毫秒字串
public static string Get_mSec()
{
string mSec = System.DateTime.Now.Millisecond.ToString();
mSec = "00" + mSec;
return mSec.Substring(mSec.Length - 3, 3);
}
// 生成 xLen 位随机字串 xRandom 为不同序号(作为种子数)
public static string Rnd_ID4(int xLen, int xRandom)
{
string oStr = "";
int nSeed = int.Parse(System.DateTime.Now.Ticks.ToString().Substring(8, 8));
double dSeed = Math.Sqrt(xRandom + 123.456) + Math.Sqrt(nSeed);
nSeed = (int)(2345678 * Math.Sqrt(dSeed));
System.Random ran = new System.Random(nSeed);
for (int i = 0; i < System.Math.Abs(xLen); i++)
{
int rin = ran.Next(0, 33 - 1);
oStr += ("0123456789ABCDEFGHJKLMNPQRSTUVWXY").Substring(rin, 1);
}
return oStr;
}
// 使用方法:
Response.Write(" <br>- ");
string StrA = "(Peace)乱码人生<br>";
string StrB = "";
for (i = 0; i < 320; i++)
{
StrB = Get_mSec() + "-" + Rnd_ID4(8, i);
if (StrA.IndexOf(StrB) >= 0)
{
Response.Write("<br>i=" + i.ToString() + " : (重复) - " + "- " + StrB);
}
else
{
StrA += StrB + "<BR>";
}
}
Response.Write(" <br><br><br> ");
Response.Write(StrA);
Response.Write(" <br><br><br> ");
Asp.net生成随机不重复的函数(方法)的更多相关文章
- php生成随机password的几种方法
文章来源:PHP开发学习门户 地址:http://www.phpthinking.com/archives/523 使用PHP开发应用程序,尤其是站点程序.经常须要生成随机password,如用户注冊 ...
- c 生成随机不重复的整数序列
#include <stdio.h> #include <malloc.h> #include <stdlib.h> #include <time.h> ...
- Python生成随机不重复姓名昵称
姓采用百家姓,名字从常用名字高频字选取两个汉字,再和当前时间戳组合,估计应该是不会重复了,代码如下: # -*- coding:utf-8 -*- import random import time ...
- sql生成随机不重复字符串 可指定长度
存储过程: create procedure dbo.GetRandStr () output) AS BEGIN ), ), @ss varchar DECLARE @I INTEGER, @cou ...
- 1.java生成随机不重复10位字符串
package org.changneng.util; import java.util.Random; public class A { public static void main(String ...
- C#Random随机值重复的解决方法
使用如上图所示的代码,将会出现如下情况,明明是随机,可值都是同样的,这样的随机几率也太小了,所以估计是代码有问题. 于是搜索了下,发现引起这个问题的原因是C#中的Random是根据时间来产生随机数,而 ...
- python生成随机整数
python生成随机不重复的整数,用random中的sample index = random.sample(range(0,10),10) 上面是生成不重复的10个从1~10的整数 python生成 ...
- PHP 生成随机字符串与唯一字符串
说明:生成随机字符串用到的方法有 mt_rand() 生成唯一字符串用到的方法有 md5(),uniqid(),microtime() 代码: <?php /* * 生成随机字符串 * @par ...
- Python threading 单线程 timer重复调用函数
项目中需要使用定时器,每次都使用构造器函数调用: timer = threading.Timer(timerFlag, upload_position) timer.start() 打印线程后发现,每 ...
随机推荐
- Struts2动态调用DMI及错误解决方法
在Strust2中action可以定义自己的方法,调用方法有两种方式,一种方式是struts.xml中指定method来表示需要用到的方法, 但是这种方法缺点在于如果你的Action中有很多方法则要多 ...
- 动态执行linq 语句 NLinq
using Evaluant.NLinq.Memory;using System.Collections.Generic;using Evaluant.NLinq;using System.Colle ...
- PHP $_SERVER的详细参数及说明
$_SERVER['PHP_SELF']#当前正在执行脚本的文件名,与documentroot相关. $_SERVER['argv']#传递给该脚本的参数. $_SERVER['argc']#包含传递 ...
- Linux学习笔记:CentOS安装MySQL
[1]安装版本: 1.1 CentOS-7-x86_64-Everything-1503-01 1.2 MySQL-5.6.27-1.linux_glibc2.5.x86_64.rpm-bund ...
- [Hive - LanguageManual] Create/Drop/Alter Database Create/Drop/Truncate Table
Hive Data Definition Language Hive Data Definition Language Overview Create/Drop/Alter Database Crea ...
- JDBC学习笔记(10)——调用函数&存储过程
如何使用JDBC调用存储在数据库中的函数或存储过程: * 1.通过COnnection对象的prepareCall()方法创建一个CallableStatement * 对象的实例,在使用Con ...
- Session,Cookie 和local storage的区别
以前从没有听说过local storage, 在网上查了一些资料,得到如下结论 从存储位置看,分为服务器端存储和客户端存储两种 服务器端: session 浏览器端: cookie, localSto ...
- 转载 SQL Server中索引管理之六大铁律
转载原地址 http://jingyan.baidu.com/article/48a42057c03bd7a924250429.html 索引是以表列为基础的数据库对象.索引中保存着表中排序的索引列, ...
- [转]Oracle关于null的处理
转至:http://www.2cto.com/database/201209/157606.html 关于空值null的排序问题 Oracle排序中NULL值处理的五种常用方法: 1.缺省O ...
- android Studio gradle so的加载
最近在使用Android Studio开发android项目,我的项目是由gradle构建的,gradle的优势文档上有说明,当你不断使用中,我越来越发现,太TMD方便啦,优势大大的明显. 打包,功能 ...