Java examples for 2D Graphics:Image Captcha
random Code
//package com.java2s; import java.util.Random; public class Main { public static void main(String[] argv) throws Exception { int count = 2; System.out.println(randomCode(count)); }// ww w. j ava2 s . c o m private static final String RANDOM_STRS = "0123456789"; public static StringBuffer randomCode(int count) { StringBuffer sb = new StringBuffer(); Random r = new Random(); for (int i = 0; i < count; i++) { int num = r.nextInt(RANDOM_STRS.length()); sb.append(RANDOM_STRS.charAt(num)); } return sb; } }