// 生成三位毫秒字串 
        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. rfid 门卡系统和人体红外感应开发

    今天忙了一天了,因为毕昇杯我发现如果不加把劲,可能寒假之前代码搞不出了,今天突击了两个模块,一个人体感应模块,和rfid刷卡模块,这两个模块谈不上自己编写代码,今天的任务也仅仅是看懂了代码,现在我总结 ...

  2. Fedora22(Gnome桌面)安装Chrome

    1.从官网上(http://www.google.cn/chrome/)下载到相对应系统版本的rpm包.这里我的是: google-chrome-stable_current_x86_64.rpm 此 ...

  3. Ineligible Devices 不被识别的设备

    设备不可用,出现Ineligible Devices,如下图: 此错误因为 Xcode的Deployment Target 大于设备的,选择和设备一样活着低于设备的.如下图:

  4. Android 用MediaCodec实现视频硬解码(转)

    本文向你讲述如何用android标准的API (MediaCodec)实现视频的硬件编解码.例程将从摄像头采集视频开始,然后进行H264编码,再解码,然后显示.我将尽量讲得简短而清晰,不展示 那些不相 ...

  5. CodeForces 455A Boredom (DP)

    Boredom 题目链接: http://acm.hust.edu.cn/vjudge/contest/121334#problem/G Description Alex doesn't like b ...

  6. Linux下的进程管理

    在操作系统系统中,进程是一个非常重要的概念. 一.Linux中进程的相关知识 1.什么是进程呢? 通俗的来说进程是运行起来的程序.唯一标示进程的是进程描述符(PID),在linux内核中是通过task ...

  7. 数据持久化之sharedpreference的使用

    要将数据持久化到手机移动设备有多种方法,其中有一种是通过sharedpreference来实现. 首先将sharedpreference初始, private SharedPreferences sp ...

  8. jq倒计时

    var referTime = 5; setInterval("refer('#show')", 1000); function refer(obj){ if(referTime ...

  9. 《精通ASP.NET MVC5》第2章 第一个MVC应用程序

      控制器     public class NewHomeController : Controller     {         // GET: /NewHome/         public ...

  10. iOS中多控制器的使用

    通常情况下,一个app由多个控制器组成,当app中有多个控制器的时候,我们就需要对这些控制器进行管理. 在开发过程中,当有多个View时,可以用一个大的view去管理多个小的view,控制器也是如此, ...