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() 打印线程后发现,每 ...
随机推荐
- 修改Android手机的“虚拟机堆大小”和android:largeHeap来防止APP内存溢出问题
使用“RAM Manager”修改“虚拟机堆大小”为某一个阀值 xxMB大小 修改 AndroidManifest.xml 里的 Application 标签的属性 android:largeHeap ...
- C#汉字转换拼音技术详解
C#汉字转换拼音技术详解(高性能) 下面将源代码贴出.public static class ChineseToPinYin { private sta ...
- 【C++对象模型】构造函数语意学之二 拷贝构造函数
关于默认拷贝构造函数,有一点和默认构造函数类似,就是编译器只有在[需要的时候]才去合成默认的拷贝构造函数. 在什么时候才是[需要的时候]呢? 也就是类不展现[bitwise copy semantic ...
- andriod的简单用法1
1.从一个Activity跳转到另一个Activity,使用Intent. 在按钮的onClick中如下写法: public void Login(View view) { Intent intent ...
- 多校5 1001 HDU5781 ATM Mechine 记忆化搜索+概率
// 多校5 1001 HDU5781 ATM Mechine // http://acm.hdu.edu.cn/search.php?field=problem&key=2016+Multi ...
- Tkinter教程之Event篇(1)'
本文转载自:http://blog.csdn.net/jcodeer/article/details/1823544 ''Tkinter教程之Event篇(1)'''# 事件的使用方法'''1.测试鼠 ...
- web.py实现jsonp
浏览器端请求 $.getJSON("/currenttime?callback=?", function (json){ $("#time").html(jso ...
- ES6学习小计
1.增加了for of语法,对应C#里的foreach,注意ES5中的 for in只会传递0,1,2.....序号,并且是字符for-of循环语句通过方法调用来遍历各种集合.数组.Maps对象.Se ...
- Gym 100507H Pair: normal and paranormal (贪心)
Pair: normal and paranormal 题目链接: http://acm.hust.edu.cn/vjudge/contest/126546#problem/H Description ...
- hdu 2063 过山车(匈牙利算法模板)
http://acm.hdu.edu.cn/showproblem.php?pid=2063 过山车 Time Limit: 1000/1000 MS (Java/Others) Memory ...