Java randomly generates Chinese characters (using high-low transcoding)

Source: Internet
Author: User

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)

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.