C # generates non-repeating random string classes

Source: Internet
Author: User

This example describes C # generation of non-repeating random string classes. Share to everyone for your reference. Specific as follows:

This C # class is used to randomly generate non-repeating strings, you can specify a range of strings, you can specify the length of the string to be generated

Using System;namespace dotnet.utilities{public class Randomoperate {//One: randomly generates a non-repeating numeric string private int rep = 0; public string generatecheckcodenum (int codecount) {string str = string.      Empty;      Long num2 = DateTime.Now.Ticks + this.rep;      this.rep++; Random random = new Random (((int) (((ULONG) num2) & 0xffffffffL) |      (int) (num2 >> this.rep)); for (int i = 0; i < Codecount; i++) {int num = random.        Next (); str = str + ((char) (0x30 + ((ushort) (num% 10))).      ToString ();    } return str; }//Method Two: randomly generated strings (mixed numbers and letters) public string generatecheckcode (int codecount) {string str = string.      Empty;      Long num2 = DateTime.Now.Ticks + this.rep;      this.rep++; Random random = new Random (((int) (((ULONG) num2) & 0xffffffffL) |      (int) (num2 >> this.rep));        for (int i = 0; i < Codecount; i++) {char ch; int num = random.        Next (); if (num% 2) = = 0) {ch = (cHAR) (0x30 + ((ushort) (num% 10));        } else {ch = (char) (0x41 + ((ushort) (num% 0x1a)); } str = str + ch.      ToString ();    } return str;    } #region///<summary>///The string of the specified number from the string.     </summary>//<param name= "Allchar" ></param>//<param name= "Codecount" ></param> <returns></returns> private String Getrandomcode (string allchar, int codecount) {//string      Allchar = "1,2,3,4,5,6,7,8,9,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z";      string[] Allchararray = Allchar.split (', ');      String randomcode = "";      int temp =-1;      Random rand = new Random (); for (int i = 0; i < Codecount; i++) {if (temp! =-1) {rand = new Random (temp * i * (int)        DateTime.Now.Ticks)); } int t = rand.        Next (allchararray.length-1); while (temp = = t) {t = rand. Next (Allchararray.length-1);        } temp = t;      Randomcode + = allchararray[t];    } return Randomcode; } #endregion}}

I hope this article is helpful to everyone's C # programming.

In addition to the Declaration,Running GuestArticles are original, reproduced please link to the form of the address of this article
C # generates non-repeating random string classes

This address: http://www.paobuke.com/develop/c-develop/pbk23080.html






Related content using regular expressions in C # to verify Chinese characters (instance code) in C # internal keyword Summary A C # class that reads and writes CSV files general structure and program writing format specification for C # programming
C # Cinema Ticketing system Graduation Design (1) C # method for generating Code39 barcodes instead of barcode fonts C # Method of encrypting large files with DES encryption algorithm C # The implementation method of calling the parent class by a subclass

C # generates non-repeating random string classes

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.