Java tutorial
//package com.java2s; import java.util.Random; import android.util.Log; public class Main { protected static final String TAG = "CommonUtil"; /** * Get a random number within a given upper limit; */ public static int getRandomInt(int max) throws Exception { int ret; Random r = new Random(); ret = r.nextInt(max); Log.i(TAG, String.format("Generate an integer value: %d", ret)); return ret; } /** * Get a random number within a given range; */ public static int getRandomInt(int min, int max) throws Exception { int ret; int range = max - min; ret = (int) (Math.random() * min) + range; Log.i(TAG, String.format("Generate an integer value between %d and %d: %d", min, max, ret)); return ret; } }