Java examples for java.util:Random Int
create Random Authentication code
//package com.java2s; import java.util.Random; public class Main { public static void main(String[] argv) throws Exception { System.out.println(createAuthcode()); }//w w w. ja va 2 s . c o m public static final int AUTHCODE_LENGTH = 5; public static String createAuthcode() { Random random = new Random(); StringBuffer authcode = new StringBuffer(); for (int i = 0; i < AUTHCODE_LENGTH; i++) { authcode.append(random.nextInt(10)); } return authcode.toString(); } }