// 生成三位毫秒字串 
        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. 【LeetCode 201】Bitwise AND of Numbers Range

    Given a range [m, n] where 0 <= m <= n <= 2147483647, return the bitwise AND of all numbers ...

  2. Android 在安装完成界面,点击打开应用程序。在应用程序点击home键,再从桌面打开程序导致产生多个实例或者说程序被重复打开

    Android 在安装完成界面,点击打开应用程序.在应用程序点击home键,再从桌面打开程序导致产生多个实例或者说程序被重复打开. etong_123的专栏 - 博客频道 - CSDN.NET htt ...

  3. javascript跑马灯抽奖

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  4. Mahout分步式程序开发 聚类Kmeans(转)

    Posted: Oct 14, 2013 Tags: clusterHadoopkmeansMahoutR聚类 Comments: 13 Comments Mahout分步式程序开发 聚类Kmeans ...

  5. redo文件三

    switch logfile是一种昂贵的操作,在进行日志切换的时候,是不允许生成新的redo信息 在前台进程生成redo日志信息的时候,此时redo buffer已经分配了空间,并且在当前的redo日 ...

  6. PackageManager获取版本号

    PackageInfo代表的是关于一个包的所有信息,就相当于一个APP应用的清单文件中收集到的所有信息. 通过这个类我们就可以获取类似版本号等一些信息. /** * 得到应用程序的版本名称 */ pr ...

  7. WeChat Official Account Admin Platform API Introduction

    Keyword: WeChat API Introduction Message and GeneralAuthor: PondBay Studio[WeChat Developer EXPERT] ...

  8. bzoj 1798 [Ahoi2009]Seq 维护序列seq(线段树+传标)

    [题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=1798 [题意] 给定一个序列,要求提供区间乘/加,以及区间求和的操作 [思路] 线段树 ...

  9. 瞬间从IT屌丝变大神——分工安排

    分工安排主要包含以下内容: 公共组件(包括common.css和common.js)一人维护,各子频道专人负责,每个频道正常情况下由一人负责,要详细写明注释,如多人合作,维护的人员注意添加注释信息,具 ...

  10. hive优化之------控制hive任务中的map数和reduce数

    一.    控制hive任务中的map数: 1.    通常情况下,作业会通过input的目录产生一个或者多个map任务. 主要的决定因素有: input的文件总个数,input的文件大小,集群设置的 ...