// 生成三位毫秒字串 
        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. 跟我学机器视觉-HALCON学习例程中文详解-FUZZY检测用于开关引脚测量

    跟我学机器视觉-HALCON学习例程中文详解-FUZZY检测用于开关引脚测量 * This example program demonstrates the basic usage of a fuzz ...

  2. qqmap 的一些操作

    ; var mapcontorl = "mapContainer"; var fullscreen = false; function qqMap(options) { var t ...

  3. 检查ept

    cat /proc/cpuinfo | grep ept                                检查cpu是否支持ept cat /sys/module/kvm_intel/p ...

  4. [Java Code] 时间维度循环生成代码片段

    public static void main(String[] args) throws ParseException { String str = "20140301"; St ...

  5. [Hive - Tutorial] Built In Operators and Functions 内置操作符与内置函数

    Built-in Operators Relational Operators The following operators compare the passed operands and gene ...

  6. Selection sort

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

  7. 小C的填数游戏

    题意: 给出一张n个点的无向图 i连向i-1和i-2 边权为wij 有两个点权ai和bi ai为0或1 在给m个操作 1.将ai异或1 2.将区间x到y的点都填上一个数ci 使得Σ(bi*(ai^ci ...

  8. Spring入门(1)-第一个Spring项目

    1. 创建maven项目,maven相关配置如下: <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi= ...

  9. Educational Codeforces Round 1(C. Nearest vectors)

    题目链接:http://codeforces.com/problemset/problem/598/C 题意是给你一个数n,下面n行,每行给你横坐标x和纵坐标y(x != 0 && y ...

  10. WinAPI: FindWindow、FindWindowEx - 查找窗口

    FindWindow(   lpClassName,        {窗口的类名}   lpWindowName: PChar {窗口的标题} ): HWND;              {返回窗口的 ...