1 Java randomly generates Chinese characters2 /**3 * The principle is to find Chinese characters from the location code of Chinese characters. In the Chinese character location code, the high and the bottom position, and the simplified and traditional. The higher the probability of the traditional Chinese characters that are generated by the number of digits. 4 * So in this example, the high level from 171, the bottom position from 161, remove most of the traditional and uncommon words. But there will still be!! 5 * 6 */7 @Test8 Public voidCreate ()throwsException {9String str =NULL;Ten intHightpos, Lowpos;//define high and low positions OneRandom random =NewRandom (); AHightpos = (176 + math.abs (Random.nextint (39)));//Get high value -Lowpos = (161 + math.abs (Random.nextint (93)));//Get Low value - byte[] B =New byte[2]; theB[0] = (NewInteger (Hightpos). Bytevalue ()); -B[1] = (NewInteger (Lowpos). Bytevalue ()); -str =NewString (b, "GBk");//turn into Chinese - System.err.println (str); + } - + /** A * Rotate and zoom text at * You must use the Graphics2D class - */ - Public voidTrans (HttpServletRequest req, HttpServletResponse resp)throwsexception{ - intwidth=88; - intHeight=22; -BufferedImage img =Newbufferedimage (width, height,bufferedimage.type_int_rgb); inGraphics g =img.getgraphics (); -Graphics2D g2d =(graphics2d) G; toG2d.setfont (NewFont ("Blackbody", font.bold,17)); +Random r =NewRandom (); - for(inti=0;i<4;i++){ theString str = "" +r.nextint (10); *AffineTransform AFF =Newaffinetransform (); $Aff.rotate (Math.random (), i*18,height-5);Panax NotoginsengAff.scale (0.6+math.random (), 0.6+math.random ()); - G2d.settransform (AFF); theG2d.drawstring (str,i*18,height-5); +System.err.println ("A;:" +str); A } the g2d.dispose (); +Imageio.write (IMG, "JPEG", Resp.getoutputstream ()); -}
Java randomly generates Chinese characters (using high-low transcoding)