Java random generation of a name and corresponding Pinyin method _java

Source: Internet
Author: User
Tags set background

The example in this article describes a method for Java to randomly generate a name and corresponding pinyin. Share to everyone for your reference. as follows:

Package com.cn.wangk.util.name;
Import Java.util.Random;
Import Com.cn.wangk.util.StrTools;
  public class Chinesename {string[] sname = new string[95];
  string[] Name = new string[79];
  Private String Names;
  Private String Pid;
    Public Chinesename () {sname[0]= "white |bai";
    sname[1]= "White |bai";
    sname[2]= "Cai |cai";
    sname[3]= "Cao |cao";
    sname[4]= "Chen |chen";
    sname[5]= "Wear |dai";
    sname[6]= "Sinus |dou";
    Sname[7]= "Deng |deng";
    sname[8]= "Di |di";
    sname[9]= "Du |du";
    sname[10]= "Duan |duan";
    sname[11]= "Fan |fan";
    sname[12]= "Fan |fan";
    sname[13]= "Room |fang";
    Sname[14]= "Wind |feng";
    sname[15]= "character |fu";
    sname[16]= "Fu |fu";
    sname[17]= "High |gao";
    sname[18]= "Ancient |gu";
    sname[19]= "Guan |guan";
    sname[20]= "Guo |guo";
    sname[21]= "Mao |mao";
    Sname[22]= "Han |han";
    sname[23]= "Hu |hu";
    sname[24]= "Flower |hua";
    sname[25]= "Flood |hong";
    sname[26]= "Hou |hou";
    sname[27]= "Yellow |huang";
    sname[28]= "Jia |jia";
    Sname[29]= "Chiang |jiang";
    sname[30]= "Golden |jin";
    sname[31]= "Liao |liao"; SnamE[32]= "Beam |liang";
    Sname[33]= "Li |li";
    Sname[34]= "Lin |lin";
    sname[35]= "Liu |liu";
    sname[36]= "Dragon |long";
    sname[37]= "Land |lu";
    sname[38]= "Lu |lu";
    sname[39]= "Luo |luo";
    sname[40]= "Horse |ma";
    sname[41]= "Cow |niu";
    sname[42]= "Pang |pang";
    sname[43]= "Pei |pei";
    sname[44]= "Peng |peng";
    sname[45]= "Qi |qi";
    sname[46]= "Qi |qi";
    sname[47]= "Money |qian";
    Sname[48]= "Joe |qiao";
    sname[49]= "Qin |qin";
    sname[50]= "Qiu |qiu";
    sname[51]= "Jo |qiu";
    sname[52]= "Chou |qiu";
    sname[53]= "Sand |sha";
    sname[54]= "Shang |shang";
    sname[55]= "Still |shang";
    sname[56]= "Shao |shao";
    sname[57]= "Shen |shen";
    sname[58]= "Division |shi";
    Sname[59]= "Shi |shi";
    sname[60]= "Song |song";
    sname[61]= "Sun |sun";
    sname[62]= "Child |tong";
    Sname[63]= "million |wan";
    sname[64]= "Wang |wang";
    Sname[65]= "Wei |wei";
    Sname[66]= "Wei |wei";
    Sname[67]= "Wu |wu";
    Sname[68]= "Wu |wu";
    sname[69]= "Xiao |xiao";
    Sname[70]= "Shaw |xiao";
    sname[71]= "Item |xiang";
    sname[72]= "Xu |xu";
    sname[73]= "Xu |xu";
    sname[74]= "Xue |xue"; Sname[75]= "Yang |yang";
    sname[76]= "Sheep |yang";
    sname[77]= "Yang |yang";
    Sname[78]= "Yi |yi";
    sname[79]= "Yin |yin";
    sname[80]= "Yu |yu";
    sname[81]= "Zhao |zhao";
    sname[82]= "Clock |zhong";
    sname[83]= "Zhou |zhou";
    sname[84]= "Zheng |zheng";
    sname[85]= "Zhu |zhu";
    sname[86]= "Oriental |dongfang";
    sname[87]= "Solitary |dugu";
    sname[88]= "Murong |murong";
    sname[89]= "Ouyang |ouyang";
    sname[90]= "Sima |sima";
    sname[91]= "Simon |ximen";
    sname[92]= "Yuchisi |yuchi";
    sname[93]= "grandson |zhangsun";
    sname[94]= "Zhuge |zhuge";
    name[0]= "ai| ai ai mourning";
    name[1]= "an| Ann is familiar with";
    name[2]= "ao| ao ao Alang";
    Name[3]= "ang| ang Anglo";
    name[4]= "ba| strike pa";
    name[5]= "bai| Bai Bai";
    Name[6]= "ban| spot like";
    name[7]= "Bang| state";
    name[8]= "bei| North times the preparation";
    name[9]= "biao| Watch Biao";
    Name[10]= "bian| Edge 卞弁忭";
    name[11]= "bu| Step not";
    name[12]= "cao| Cao Xua Cao";
    name[13]= "Cang| Cang Cang";
    name[14]= "chang| Changchangchang open 玚";
    name[15]= "chi| late holding pool red ruler Chi";
    name[16]= "ci| ci ci";
    Name[17]= "du| alone";
    name[18]= "Dong| dong Dong";
    name[19]= "dou| all";
    name[20]= "fa| Hair"; NAME[21]= "fan| Fan Fan-Fan";
    name[22]= "Fang| party visits 邡 Fang";
    name[23]= "Feng| Feng seal Feng Feng Feng";
    name[24]= "fu| husband Fuffer";
    name[25]= "gao| Gao Gao picks";
    name[26]= "Hong| Hong Honghong Hong Hong Rainbow";
    name[27]= "hu| hu Hu Hu Hu presume";
    name[28]= "hua| Hua Wah";
    name[29]= "hao| Hao Hao Hao hao 淏";
    name[30]= "ji| active Ji-chi attack disease and the basis of the Tijijiki Ji Ji memorial to Ji Chi Ji Ji thistle ji Grandpro";
    name[31]= "jian| gradually Jian Jian";
    Name[32]= "kan| magazine 戡";
    Name[33]= "ke| can Keko carved ke 溘 zangke";
    name[34]= "lang| lang Lang lang Langfeng";
    name[35]= "li| calendar away from the Rillieri Li Li Lai li Lek oak glass";
    Name[36]= "Lin| Lin Lin Lin"; 
    name[37]= "ma| horse";
    name[38]= "mao| trade and the appearance of Mao Spear Mao 瑁";
    name[39]= "miao| Miao Miao";
    Name[40]= "nan| nan South";
    name[41]= "pian| piece";
    name[42]= "qian| latent Qian Xi xi Qian";
    name[43]= "Qiang| Strong Qiang 锖 玱";
    name[44]= "qin|-Qin qin RTHK";
    name[45]= "Qing| Qing Ching Ching";
    name[46]= "ran| Changan dye Burning";
    name[47]= "ren| ren ren";
    Name[48]= "sha| sand evil spirit";
    name[49]= "Shang| Shang Shang";
    name[50]= "shen| Shen Shen Shen Shen shen";
    name[51]= "shi| Shi Shi Shi when ten Shi Shi poem begins to show suitable stoneware";
    name[52]= "shui| Water";
    name[53]= "si| si silk Si Si";
    name[54]= "song| song chant";
    name[55]= "Tang| Hall Tang Yu 瑭";
    name[56]= "Tong| Shitong with Tang"; name[57]= "tian| Tian Tian Speak";
    name[58]= "wan| Wan Night";
    name[59]= "wei| Wei Weiwei Wiewei Wessing Wei as";
    name[60]= "wu| Wusheng Wu Wu Shing without E";
    Name[61]= "The xi| West Sisi washes XI to cherish";
    name[62]= "Xiao| Hsiao Shang Shaw School";
    name[63]= "Xiong| Chongxiong";
    name[64]=, "Yang Yang Yang dust 鸯" yang| sheep;
    name[65]= "yi| Yi Yi, yi yi yee yi zhi yi instrument translation Wing yi Yue yi yi yi yi yi an anecdote, Yi;"
    Name[66]= "The yin| Yin Yin 訚 the yin;
    Name[67]= "Ying| Ying Ying Ying The Shadow Ying Ying Eagle";
    Name[68]= "you|", the right worry and initiative unitary;
    name[69]= "Yu| Yu Yu is in Yu Yuyu language in the pre-feather Yu Yu yu area yu huayu 虞禺 yu Yu, Yu Huayu,"
    name[70]= "zhi| system to the value of Zhi directly to the treatment of Zhi zhi-zhi zhizhi the";
    name[71]= "Zhong| Zhong Zhong";
    Name[72]= "zhou| Zhou 胄 繇 daylight";
    name[73]= "zhu| Bamboo Lord stops Zhu Yu Zhu Aulympic";
    Name[74]= "zhuo| Zhuo hacking delaminated to be polished Zhuo";
    name[75]= "zi| zi zi, zi tzu 秭";
    name[76]= "Zong| Zong";
    name[77]= "zu| Foot Clan's ancestral stroke";
  Name[78]= "zuo| for Zolzo chisel";
    public void GetName () {Random Random = new Random ();
    int i = Random.nextint (94);
    string[] names = Strtools.split (Sname[i], "|");
    String id = names[0];
    String pid = names[1]; String[] Mingzi1 = this.
    Getnamekey ();
    id = id+mingzi1[1];
    PID = pid+mingzi1[0]; if (Random.nextint (2) ==1) {mingzi1 = this. GetnamEKey ();
      id = id+mingzi1[1];
    PID = pid+mingzi1[0]+ ","; } this.
    Names=id; This.
  Pid=pid;
    Private string[] Getnamekey () {Random Random = new Random ();
    int i = Random.nextint (78);
    string[] names = Strtools.split (Name[i], "|");
    string[] Mingzi = new string[2];
    Mingzi[0] = names[0]; MINGZI[1] = this.
    Getkey (Names[1]);
  return Mingzi;
    private string Getkey (string name) {if (Strtools.checkstrnull (name)) return null;
    int counti = Name.length ();
    Random Random = new Random ();
    int i = Random.nextint (Counti);
  Return name.substring (i,i+1); }/** * @param args */public static void main (string[] args) {//TODO automatically generate method stub//chinesename
    me = new Chinesename ();
    int j=0;
        for (int i=0;i<10000;i++) {if (j==50) {j=0;
      System.out.println ();
      } j + +;
    System.out.print (Chinesename.getname () + ",");
  } public String GetNames () {return Names; } public void Setnames (String names) {names = names;
  Public String Getpid () {return Pid;
  } public void Setpid (String pid) {pid = pid;

 }
}
<%@ page contenttype= "image/jpeg;charset=utf-8"%> <%@ page import= "java.awt.*"%> <%@ page import= " java.awt.image.* "%> <%@ page import= java.util.*"%> <%@ page import= "javax.imageio.*"%> <% @page Import= "Com.cn.wangk.util.name.ChineseName"%> <%!
    Color getrandcolor (int fc,int BC) {//The given range gets the random color Random Random = new Random ();
    if (fc>255) fc=255;
    if (bc>255) bc=255;
    int R=fc+random.nextint (BC-FC);
    int G=fc+random.nextint (BC-FC);
    int B=fc+random.nextint (BC-FC);
  return new Color (R,G,B);
  }%> <% out.clear ();
  Out=pagecontext.pushbody ()//Can (where Out,pagecontext are JSP built-in objects!)
  Set page does not cache Response.setheader ("Pragma", "No-cache");
  Response.setheader ("Cache-control", "No-cache");
  Response.setdateheader ("Expires", 0);
  Creates an image int width=100 in memory, height=35;
  BufferedImage image = new BufferedImage (width, height, bufferedimage.type_int_rgb);
  Gets the graphics context Graphics g = image.getgraphics (); Generate Random class Random Random =New Random ();
  Set Background color G.setcolor (Getrandcolor (200,250));
  G.fillrect (0, 0, width, height);
  Set font g.setfont (new font ("bold", font.plain,18));
  Randomly generated 155 interference lines, so that the authentication code in the image is not easy to be detected by other programs G.setcolor (Getrandcolor (160,200));
    for (int i=0;i<155;i++) {int x = random.nextint (width);
    int y = random.nextint (height);
    int xl = Random.nextint (12);
    int yl = Random.nextint (12);
  G.drawline (X,y,x+xl,y+yl);
  } chinesename chinesename = new Chinesename ();
  Chinesename.getname ();
  String SRand = Chinesename.getnames ();
  String pid = Chinesename.getpid ();
  G.setcolor (New Color (20+random.nextint), 20+random.nextint (a), 20+random.nextint (110));
  G.setcolor (Color.Black);
  g.DrawString (srand,5,18);
  G.setfont (New Font ("bold", font.plain,12));
  g.DrawString (pid,5,30);
  Draw a Border G.setcolor (Color.Black);
  G.drawrect (0,0,width-1,height-1);
  The authentication code stored in the session to prevent theft, you can use the key to encrypt Session.removeattribute ("Gsrand");
  Session.setattribute ("Gsrand", SRand); Image effective G.disposE ();

 Output image to page imageio.write (image, "JPEG", Response.getoutputstream ());%>

I hope this article will help you with your Java programming.

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.