C # Randomly produces commonly used Chinese characters

Source: Internet
Author: User

Principle please refer to the article below: The basic principle of generating random Chinese character verification code with C #Chinese Character Location Code tableThe relationship between the location code, GB code and the internal code of the machine
1 The Location code is first converted into a hexadecimal number representation
(2) (the hexadecimal representation of the location Code) +2020h= GB code;
(3) GB Code +8080h= machine inner Code
For example, in the case of "Da" in Chinese characters, the area code of "Da" is 2083
1, the area code is 20, the bit number is 83
2. Convert location number 2083 to hexadecimal representation as 1453H
3, 1453H+2020H=3473H, get GB code 3473H
4, 3473H+8080H=B4F3H, get the internal code of the machine for B4F3H
Commonly used Chinese characters in 16-55 districts, of which 55 have a few empty, it should be removed.  ///<summary>///randomly produce common Chinese characters///</summary>///<param name= "Count" > to produce the number of Chinese characters </param>/// ;returns> Common Chinese characters </returns> private list<string> generatechinesewords (int count) {list<string> Chinesewords = new list<string> (); Random rm = new Random (); Encoding gb=encoding.getencoding ("gb2312"); for (int i = 0; i < count; i++) {//Get region code (the region code range for common Chinese characters is 16-55) int regioncode = RM. Next (16, 56); Gets the bit code (the bit range is 1-94 because the 90,91,92,93,94 of the 55 zone is empty, therefore excludes it) int positioncode; if (Regioncode = = 55) {//area 55 excludes 90,91,92,93,94 Positioncode = rm. Next (1, 90); else {Positioncode = rm. Next (1, 95); //Convert Location code to internal code int regioncode_machine = Regioncode + 160;//160 that is 16 20h+80h=a0h int positioncode_machine = Positioncode + 160;//160 is 16 20h+80h=a0h//Convert to Kanji byte[] bytes = new byte[] {(byte) regioncode_machine, (byte) Positioncode_machine} ; Chinesewords.add (GB. GetString (bytes)); return chinesewords; }

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.