Android examples for java.util:Random String
get random string for Captcha
import android.content.Context; import android.provider.Settings; import android.telephony.PhoneNumberUtils; import java.io.File; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; import java.util.Random; import java.util.TimeZone; import java.util.regex.Matcher; import java.util.regex.Pattern; public class Main{ public static String getCaptcha() { Random rd = new Random(System.currentTimeMillis()); StringBuilder strBuilder = new StringBuilder(""); String tmp = new String("123456789abcdefghijklmnopqrstuvwxyz"); for (int i = 0; i < 8; i++) { strBuilder.append(tmp.charAt(rd.nextInt(35))); }/*from ww w .jav a2s.c om*/ return strBuilder.toString(); } }