Java tutorial
//package com.java2s; //License from project: LGPL import java.util.Calendar; public class Main { /** * This method is used to generate random number between given range. */ public static long getRandomNumberBetween() { Calendar rightNow = Calendar.getInstance(); long offset = rightNow.get(Calendar.ZONE_OFFSET) + rightNow.get(Calendar.DST_OFFSET); long sinceMidnight = (rightNow.getTimeInMillis() + offset) % (24 * 60 * 60 * 1000); return sinceMidnight; } }