// 生成三位毫秒字串 
        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生成随机不重复的函数(方法)的更多相关文章

  1. php生成随机password的几种方法

    文章来源:PHP开发学习门户 地址:http://www.phpthinking.com/archives/523 使用PHP开发应用程序,尤其是站点程序.经常须要生成随机password,如用户注冊 ...

  2. c 生成随机不重复的整数序列

    #include <stdio.h> #include <malloc.h> #include <stdlib.h> #include <time.h> ...

  3. Python生成随机不重复姓名昵称

    姓采用百家姓,名字从常用名字高频字选取两个汉字,再和当前时间戳组合,估计应该是不会重复了,代码如下: # -*- coding:utf-8 -*- import random import time ...

  4. sql生成随机不重复字符串 可指定长度

    存储过程: create procedure dbo.GetRandStr () output) AS BEGIN ), ), @ss varchar DECLARE @I INTEGER, @cou ...

  5. 1.java生成随机不重复10位字符串

    package org.changneng.util; import java.util.Random; public class A { public static void main(String ...

  6. C#Random随机值重复的解决方法

    使用如上图所示的代码,将会出现如下情况,明明是随机,可值都是同样的,这样的随机几率也太小了,所以估计是代码有问题. 于是搜索了下,发现引起这个问题的原因是C#中的Random是根据时间来产生随机数,而 ...

  7. python生成随机整数

    python生成随机不重复的整数,用random中的sample index = random.sample(range(0,10),10) 上面是生成不重复的10个从1~10的整数 python生成 ...

  8. PHP 生成随机字符串与唯一字符串

    说明:生成随机字符串用到的方法有 mt_rand() 生成唯一字符串用到的方法有 md5(),uniqid(),microtime() 代码: <?php /* * 生成随机字符串 * @par ...

  9. Python threading 单线程 timer重复调用函数

    项目中需要使用定时器,每次都使用构造器函数调用: timer = threading.Timer(timerFlag, upload_position) timer.start() 打印线程后发现,每 ...

随机推荐

  1. Web自动化框架搭建——前言

    1.web测试功能特性 a.功能逻辑测试(功能测试),这一块所有系统都是一致的,比如数据的添加.删除.修改:功能测试案例设计感兴趣和有时间的话可以另外专题探讨: b.浏览器兼容性测试,更重要的是体验这 ...

  2. Spring 定时任务的实现<转>

    本人暂时用到的实现定时任务的方式有2种 一.注解方式实现,简单方便 1:在applicationContext.xml中加入下面的配置, 这是spring的组件扫描,保证含有定时任务的类,能被spri ...

  3. 根据给定的日期给 dateEdit 控件增加颜色

    private void dateEdit1_DrawItem(object sender, DevExpress.XtraEditors.Calendar.CustomDrawDayNumberCe ...

  4. .net中的"异步"-手把手带你体验

    周二刚过,离5.1小长假还有那么一阵,北京的天气已经开始热起来了.洗完澡,突然想起博客园一位大哥暂称呼元哥吧,当时我写了一篇windows服务的安装教程(http://www.cnblogs.com/ ...

  5. select XXX into 和 Insert into XXX select

    检索一个表中的部分行存到另一张表中. 一 .另外的那张表没有新建的时候,使用 select XXX into,创建的表与原表有相同的列名和类型: select * into Departments_C ...

  6. java计时代码

    public class Test{ public static void main(String[] args) { long startMili=System.currentTimeMillis( ...

  7. RestTemplate中文乱码问题

    使用RestTemplate传输带有图片的表单时,需要对表单中的中文参数进行URL编码, eg :URLDecoder.decode(name);               // 使用默认的解码   ...

  8. memcache和memcahced区别

    在写这篇文章之前一直对memcache .memcahced模糊,相差一个字母,特此总结下: Memcache是什么? Memcache是一个自由和开放源代码.高性能.分配的内存对象缓存系统.用于加速 ...

  9. work7

    uno. 理解C++变量的作用域和生命周期 没有要求讲解我就简单注释了一下~ #include <iostream>int main(){ for (int i=0;i<10;i++ ...

  10. HDU 5742 It's All In The Mind (贪心)

    It's All In The Mind 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5742 Description Professor Zhan ...