. NET (C #) generates random names, the generation of random Chinese characters __.net

Source: Internet
Author: User
. NET (C #) generates random names, and random Chinese characters are produced the generation of random Chinese characters
 public static object[] Createregioncode (int strlength, bool Israndomcount = False) {if (Israndomcount) {
         Random Random = new Random (); Strlength = random.
     Next (1, strlength + 1); }//define a string array to store the constituent elements of the encoding string[] rbase = new String[16] {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a
     "," B "," C "," D "," E "," F "};
     Random rnd = new Random ();
     Define an object array to object[] bytes = new Object[strlength];
     /* Generate a hexadecimal byte array with two elements at a time, and put it into the bject array each Chinese character has four location codes. Location Code 1th and location code 2nd bit as byte array first element location code 3rd bit and Location code 4th bit as the second element of the byte array * for (int i = 0; i < strlength i++) {//Location code 1th bit int r1 = rnd.
         Next (11, 14); String str_r1 = Rbase[r1].
         Trim ();
         Location Code 2nd bit rnd = new Random (R1 * Unchecked ((int) DateTime.Now.Ticks) + i);//Replace the seed of the random number generator to avoid duplicate value int R2; if (r1 =) {r2 = rnd.
         Next (0, 7); else {r2 = rnd.
         Next (0, 16); } string str_r2 = Rbase[r2].
         Trim ();
         Location Code 3rd bit rnd = new Random (R2 * Unchecked ((int) DateTime.Now.Ticks) + i); int r3 = rnd.
         Next (10, 16); String str_r3 = Rbase[r3].
         Trim ();
         Location Code 4th bit rnd = new Random (R3 * Unchecked ((int) DateTime.Now.Ticks) + i);
         int R4; if (R3 = =) {R4 = rnd.
         Next (1, 16); else if (r3 =) {R4 = rnd.
         Next (0, 15); else {r4 = rnd.
         Next (0, 16); } string str_r4 = Rbase[r4].
         Trim ();
         Define two byte variable storage generated random Chinese character location code byte byte1 = convert.tobyte (str_r1 + str_r2, 16);
         byte Byte2 = convert.tobyte (Str_r3 + STR_R4, 16);
         Store two byte variables in a byte array byte[] Str_r = new byte[] {byte1, byte2}; Bytes A byte array of the resulting Chinese character into an object array.
     SetValue (Str_r, i);
 return bytes; }
Last name get
  public static string Getsurname () {Random Random = new Random (); int index = random. Next (0, surname.
      Count ());
  return Surname[index]; public static list<string> surname = new List<string> () {"Zhao", "Money", "Sun", "Li", "Zhou", "WU", "Zheng", "Wang", "Feng", "Chen" , "Chu", "Wei", "Jiang", "Shen", "Han", "Yang", "Zhu", "Qin", "especially", "Xu", "Ho", "Lu", "Shi", "Zhang", "Hole", "Cao", "Yan", "Hua", "Jin", "Wei", "Tao", "Ginger", "qi", " Xie ", Zou", "Yu", "Bai", "Shui", "Dou", "Zhang", "Yun", "su", "Pan", "GE," XI "," fan "," Peng "," Lang "," Lu "," Wei "," Chang "," Ma "," Miao "," Feng "," Hua "," Fang "," Yu ","  Ren "," Yuan "," Liu "," Feng "," Bao "," History "," Tang "," fee "," cheap "," cen ", Xue", "Lei", "he", "ni", "Tang", "Teng", "Yin", "Luo", "bi", "Hao", "WU", "Ann", "Chang", "le",  "In", "when", "Fu", "Skin", "Bian", "Qi", "Kang", "WU", "Yu", "Yuan", "bu", "gu", "Meng", "ping", "Huang", "and", "Mu", "Xiao", "Yin", "Yao", "Shao", "Zhan", "Wang", "Taiqi", "Mao", "Yu", "Di", "M", "Bei", "Ming", "Zang", "Count", "Fu", "into", "Dai", "Talk", "song", "Mao", "Pang", "Bear", "Ji", "Shu", "Qu", "item", "Zhu", "Dong", "Liang", "Du "," Ruan "," Blue "," min "," Mat "," Quarter "," hemp "," strong "," Jia "," Road "," Lou "," Danger "," Jiang "," Tong "," Yan "," Guo "," Mei "," Sheng "," Lin "," Diao "," Chung "," Xu ","Qiu", "Luo", "Gao", "Xia", "Cai", "Tian", "fan", "Hu", "Ling", "Huo", "Yu", "Million", "Zhi", "Ke", "昝", "tube", "Lou", "Mo", "Jing", "Room", "Jo", "Bartholomew", "dry", "solution", "Shall", "Zong", "Ding", "Xuan", "Ben", "Deng", "Yu", "single", "Hang", "Hong," Bao "," Zhu "," Zuo "," Shi "," Cui "," Ji "," button "," Gong "," Cheng "," Ma "," Xing "," slippery "," Pei "," Lu " , "Rong", "Weng", "Xun", "sheep", "on", "Hui", "Zhen", "麹", "Home", "seal", "Rui", "Yi", "Chu", "Jin", "Ji", "Bing", "mi", "Pine", "Well", "Duan", "Fu", "WU", "WU", "Jiao" , "ba", "Bow", "Shepherd", "Kui", "Mountain", "valley", "car", "Hou", "mi", "Peng," all "," Astrid "," ban "," Yang "," Autumn "," Zhong "," Yi "," palace "," Ning "," Revenge "," Luan "," Violence "," Gan "," Oblique "," Li "," Rong "," zu "," WU "," Fu "," Liu "," Jing "," Zhan "," bundle "," Dragon "," Ye "," Lucky "," secretary "," Shao "," Gao "," Li "," thistle "," thin "," Yin "," bed "," white "," Huai "," Pu ","  Tai "," from "," e "," Rope "," salty "," nationality "," Lai "," Zhuo "," Rush "," Tu, "Meng", "Chi", "Joe", "Yin", "Yu", "Xu", "Can", "Cang", "double", "smell", "xin", "Party", "Zhai", "Tan",  "Gong", "Lao", "逄", "Ji", "Shen", "Help", "plugging", "ran", "Slaughter", "Li," Yong "," but "," 璩 "," Mulberry "," GUI "," Pu "," Niu "," Shou "," Tong "," Bian "," Hu "," Yan "," Ji "," Jia ", "Pu", "Shang", "Nong", "Wen", "Don't", "Zhuang", "Yan", "Chai", "Qu", "Yan," charge "," Mu "," Lian "," Ru "," Xi "," Huan "," AI "," Fish "," Rong "," to "," gu "," Yi "," cautious "," ge "," Liao "," Yu "," End "," Jinan ","Habitat, "Heng", "step", "All", "Geng", "full", "Hiro", "Kuang", "Country", "Wen," Kou "," Guang "," Lu "," que "," dong "," ou "," 殳 "," Wo "," Li "," Wei "," Yue "," Kui "," Long "," Division ",  "Gong", "she", "nie", "Chao Buzhi", "Hook", "AO", "Rong", "cold", "assailable", "Xin", "Kanbao", "that", "Jane", "Rao", "Empty", "Zeng", "No", "Sha", "Mie", "Nourishing", "Ju", "must", "Feng", "nest", "Guan", "Quine", "phase", "Cha", "Hou", "Jing", "Red", "swim", "aulympic", "right", "Alex", "Gai", "Yi", "Huan", "Gong", "Zhang", "Governor", "Jin", "Chu", "Yan", "fa", "Ru", "Yan", "tu "," Chin "," Yue "," Shuai "," 缑 "," Kang "," condition "," hou "," There "," Qin "," Return "," sea "," ink "," Ha "," Qiao "," Da "," Year "," Love "," Yang "," Tong "," Shang "," Mu "," Di She "," 佴 "," bo "," reward "," after "," Sima "," Officer "," Ouyang "," Xia-hou "," Zhuge "," Wenren "," Oriental "," Hector Lian "," Huang Fu "," Yuchisi "," Ram "," Dan Tai "," Gong Ye "," Huizong "," Puyang "," Chun Yu "," Chanyu "," too "Uncle", "Shen", "Gongsun", "Dongsun", "Xuan Yuan", "Linghutao", "Chung", "nonfictional", "grandson", "Murong", "Sainus", "Lu Qiu", "situ", "Sikong", "not official", "vacant", "Son car", "micro-health", "Zhuan Sun", "Duanmu", "Witch", "Gong Xi", "carved lacquer", "Le Zheng", "the Soil 驷", "Gong Liang", "Tuo Pull", "clip gu", "Kill Father", "Guliangzhuan", "Duan Gan", "Bai", "Dong Guo", "South Gate", "Huyan", "Goat tongue", "according", "Left Mound", "East Gate", "Simon", "Nangong"};
examples of working with effects:

Use:

for (int j = 0; J < + j)
{
    //surname
    string surname = Chinesename.getsurname ();
    Gets the GB2312 encoding page (table)
    Encoding GB = encoding.getencoding ("gb2312");
    The call function produces 4 random Chinese encoding
    object[] bytes = Chinesename.createregioncode (2, true);
    Decodes the Chinese character
    string name = string according to the encoding byte array. Empty;
    for (int i = 0; i < bytes. Length; i++)
    {
        name + GB. GetString ((byte[]) Convert.changetype (Bytes[i], typeof (byte[)));
    Console.WriteLine ($ "{surname} {name}");
    Thread.Sleep (MB);

Effect:

Description: Here is a small problem, if not delayed 100ms, will produce the same name, for unknown reasons. attached:

reference 1:http://www.cnblogs.com/angelfeather/archive/2008/02/02/1062147.html

Reference 2:

Related Article

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.