Java randomly generates a name and the corresponding pinyin method

  • 2020-04-01 04:02:48
  • OfStack

This article illustrates how Java randomly generates a name and its corresponding pinyin. Share with you for your reference. The details are 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]=" DE |di";
    sName[9]=" du |du";
    sName[10]=" Period of |duan";
    sName[11]=" van |fan";
    sName[12]=" fan |fan";
    sName[13]=" room |fang";
    sName[14]=" The wind |feng";
    sName[15]=" operator |fu";
    sName[16]=" blessing |fu";
    sName[17]=" high |gao";
    sName[18]=" The ancient |gu";
    sName[19]=" guan |guan";
    sName[20]=" guo |guo";
    sName[21]=" MAO |mao";
    sName[22]=" Korea |han";
    sName[23]=" hu |hu";
    sName[24]=" flowers |hua";
    sName[25]=" hong |hong";
    sName[26]=" hou |hou";
    sName[27]=" huang |huang";
    sName[28]=" jia |jia";
    sName[29]=" jiang |jiang";
    sName[30]=" gold |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]=" lu |lu";
    sName[38]=" Lou |lu";
    sName[39]=" ROM. |luo";
    sName[40]=" The horse |ma";
    sName[41]=" The 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]=" The qin dynasty |qin";
    sName[50]=" The high |qiu";
    sName[51]=" cho |qiu";
    sName[52]=" revenge |qiu";
    sName[53]=" sand |sha";
    sName[54]=" shang |shang";
    sName[55]=" It is |shang";
    sName[56]=" shao |shao";
    sName[57]=" shen |shen";
    sName[58]=" t |shi";
    sName[59]=" shi |shi";
    sName[60]=" The song dynasty |song";
    sName[61]=" Sun. |sun";
    sName[62]=" Children's |tong";
    sName[63]=" wan |wan";
    sName[64]=" The king |wang";
    sName[65]=" wei |wei";
    sName[66]=" who |wei";
    sName[67]=" wu |wu";
    sName[68]=" wu |wu";
    sName[69]=" Shaw, |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]=" The sheep |yang";
    sName[77]=" Yang |yang";
    sName[78]=" easy |yi";
    sName[79]=" Yin |yin";
    sName[80]=" yu |yu";
    sName[81]=" zhao |zhao";
    sName[82]=" The clock |zhong";
    sName[83]=" weeks |zhou";
    sName[84]=" zheng |zheng";
    sName[85]=" zhu |zhu";
    sName[86]=" The east |dongfang";
    sName[87]=" dugu |dugu";
    sName[88]=" Mr. Murong |murong";
    sName[89]=" ouyang |ouyang";
    sName[90]=" Si ma |sima";
    sName[91]=" the west gate |ximen";
    sName[92]=" WeiChi |yuchi";
    sName[93]=" grandson |zhangsun";
    sName[94]=" The various ge |zhuge";
    Name[0]="ai| Ai ai ai ";
    Name[1]="an| Ann dark command ";
    Name[2]="ao| Ao ao ao ao ao ";
    Name[3]="ang| Leon ang ";
    Name[4]="ba| Bully" ";
    Name[5]="bai| White hk ";
    Name[6]="ban| Spot, ";
    Name[7]="bang| The state ";
    Name[8]="bei| North times the case ";
    Name[9]="biao| Biao biao biao biao biao ";
    Name[10]="bian| Edge "bian chemical Bian ";
    Name[11]="bu| Don't step ";
    Name[12]="cao| Cao cao cao grass ";
    Name[13]="cang| Pale warehouse ";
    Name[14]="chang| Chang chang chang ";
    Name[15]="chi| Chi chi chi chi chi chi chi chi chi chi ";
    Name[16]="ci| The words were kind ";
    Name[17]="du| All alone ";
    Name[18]="dong| Dong dong ";
    Name[19]="dou| all ";
    Name[20]="fa| Hair lack of purity ";
    Name[21]="fan| Fan fan fan fan fan ";
    Name[22]="fang| Party to visit Fang � ";
    Name[23]="feng| Feng feng feng feng feng feng feng feng feng ";
    Name[24]="fu| Operator, fu ";
    Name[25]="gao| Gao Gao GaoGao ";
    Name[26]="hong| Hong hong hong hong hong hong hong hong hong hong ";
    Name[27]="hu| Hu hu hu hu hu hu hu hu hu hu ";
    Name[28]="hua| Hua hua hua hua hua hua hua hua ";
    Name[29]="hao| Hao hao hao hao hao hao hao hao hao hao hao ";
    Name[30]="ji| JiJi active set of dhi combat disease and remember the auspicious meter offering international record performance ji ji ji ji ji ji ji Ji generic Ji odd wall shu ji ji ";
    Name[31]="jian| Jian jian jian jian jian jian jian ";
    Name[32]="kan| Publication Kan ";
    Name[33]="ke| Rocco rocco rocco rocco ";
    Name[34]="lang| Langlang langang langang ";
    Name[35]="li| Li li li li li li li li li li li li li li li li li ";
    Name[36]="lin| Early in the ";
    Name[37]="ma| The horse "; 
    Name[38]="mao| MAO MAO MAO MAO MAO MAO MAO MAO MAO ";
    Name[39]="miao| Simon are following ";
    Name[40]="nan| Nan south ";
    Name[41]="pian| Slice of the ";
    Name[42]="qian| Qian qian qian qian qian qian qian qian gan qian ";
    Name[43]="qiang| Strong qiang Qiang � ";
    Name[44]="qin| Pro qin qin jin jin ";
    Name[45]="qing| Qing city QingQing ";
    Name[46]="ran| Dye RanRan combustion ";
    Name[47]="ren| I asked benevolence blade ";
    Name[48]="sha| The sand is ";
    Name[49]="shang| On the type, ";
    Name[50]="shen| Shen shen shen shen shen shen ";
    Name[51]="shi| When teacher Shi Shi ten and poetry in comfortable standard ";
    Name[52]="shui| water ";
    Name[53]="si| Si si si si si si si si si si si si si si si si si ";
    Name[54]="song| Loose recite verses ";
    Name[55]="tang| Hall Tang Tang Tang ";
    Name[56]="tong| Tong tong tong tong tong tong ";
    Name[57]="tian| Amada your ";
    Name[58]="wan| Wan wan night ";
    Name[59]="wei| Wei wei wei wei wei wei wei wei wei wei wei wei wei wei wei wei wei ";
    Name[60]="wu| Wu wu wu wu wu wu wu wu wu wu wu wu wu wu wu wu wu wu wu wu wu wu ";
    Name[61]="xi| Xi xi xi xi xi xi xi xi xi xi xi ";
    Name[62]="xiao| Xiao xiao xiao xiao xiao xiao xiao xiao school ";
    Name[63]="xiong| kumao ";
    Name[64]="yang| Yang Yang Yang Yang Yang Yang Yang Yang Yang Yang Yang Yang Yang ";
    Name[65]="yi| Easy meaning according to yi yi also leaning YiYiYi instrument art wing zhun yi yi bright translation interpretation h taken yi yi implement proliferation until Yi next year ";
    Name[66]="yin| Yin Yin Yin Yin Yin Yin Yin Yin Yin Yin ";
    Name[67]="ying| Ying ying ying ying ying ying ying ying ying ying ying ying ying eagle ";
    Name[68]="you| You u leisurely right sorrow you ";
    Name[69]="yu| Yu yu yu yu yu yu yu yu yu yu yu yu yu yu yu yu yu yu yu yu yu yu yu yu yu yu yu yu yu yu yu yu yu yu yu yu yu yu yu yu yu yu yu yu yu yu yu yu yu yu yu yu yu yu yu yu yu yu yu yu yu yu yu yu yu yu yu yu yu yu ";
    Name[70]="zhi| System to value known mass ZhiZhi straight to cure of buy cheese purport zhi zhi Zhi sceneries grilled pheasant signs ";
    Name[71]="zhong| The loyal clock longing ";
    Name[72]="zhou| Zhou zhou zhou was eaten ";
    Name[73]="zhu| The bamboo master stopped zhu zhu zhu zhu zhu zhu ";
    Name[74]="zhuo| Zhuo cooked zhuo zhuo o for cooking ";
    Name[75]="zi| Son endowment, purple appearance transcribing catalpa Zi ";
    Name[76]="zong| We can of our fir ";
    Name[77]="zu| Foot race progenitor ";
    Name[78]="zuo| As ZuoZuo Ze 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);
  }
  
  public static void main(String[] args) {
    //TODO automatically generates method stubs
    //ChineseName chineseName = 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){//Get random colors for a given range
    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 the page not to be cached
  response.setHeader("Pragma","No-cache");
  response.setHeader("Cache-Control","no-cache");
  response.setDateHeader("Expires", 0);
  //Create an image in memory
  int width=100, height=35;
  BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
  //Getting the graphics context
  Graphics g = image.getGraphics();
  //Generate random class
  Random random = new Random();
  //Setting the background color
  g.setColor(getRandColor(200,250));
  g.fillRect(0, 0, width, height);
  //Set the font
  g.setFont(new Font(" blackbody ",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(110),20+random.nextInt(110),20+random.nextInt(110)));
  g.setColor(Color.BLACK);
  g.drawString(sRand,5,18);
  g.setFont(new Font(" blackbody ",Font.PLAIN,12));
  g.drawString(pid,5,30);
  //Picture frame
  g.setColor(Color.black);
  g.drawRect(0,0,width-1,height-1);
  //The authentication code is stored in the SESSION to prevent theft and can be encrypted using the key
  session.removeAttribute("gsrand");
  session.setAttribute("gsrand",sRand);
  //The image effect
  g.dispose();
  //Output image to page
  ImageIO.write(image, "JPEG", response.getOutputStream());%>

I hope this article has been helpful to your Java programming.


Related articles: