List of usage examples for java.util Random Random
public Random()
From source file:Main.java
public static int getRandomColor() { Random rand = new Random(); return Color.argb(100, rand.nextInt(256), rand.nextInt(256), rand.nextInt(256)); }
From source file:Main.java
public static int handleRange(String string, String splitter) { Random rand = new Random(); int result;/*from w w w .ja v a 2 s . c om*/ int range; int loc; String[] splitString = string.split(splitter); if (getDouble(splitString[0], 0) > getDouble(splitString[1], 0)) { range = (int) ((getDouble(splitString[0], 0) * 100) - (getDouble(splitString[1], 0) * 100)); loc = (int) (getDouble(splitString[1], 0) * 100); } else { range = (int) ((getDouble(splitString[1], 0) * 100) - (getDouble(splitString[0], 0) * 100)); loc = (int) (getDouble(splitString[0], 0) * 100); } result = (loc + rand.nextInt(range + 1)) / 100; return result; }
From source file:Main.java
public static byte[] getRandomBuffer(int size) { byte[] buffer = new byte[size]; Random random = new Random(); random.nextBytes(buffer);/*from w w w .ja v a 2s . co m*/ return buffer; }
From source file:Main.java
public static int getRandom(int min, int max) { Random random = new Random(); int s = random.nextInt(max) % (max - min + 1) + min; return s;//from w w w .j av a 2 s. c o m }
From source file:Main.java
public static int ramdomMinMax(int min, int max) { Random random = new Random(); int rs = -1;/*w ww . j a v a2 s . c o m*/ while (rs < min || rs > max) { rs = random.nextInt(max); } return rs; }
From source file:Main.java
public static float ramdomMinMaxFloat(float min, float max) { Random random = new Random(); float rs = -1; while (rs < min || rs > max) { rs = random.nextFloat();/*w ww.ja v a 2 s . c om*/ } return rs; }
From source file:com.play.engine.RecommendEngine.java
public static void main(String[] args) { ShopSearchClient client = new ShopSearchClient(); double lng = 116.487823; double lat = 39.88445; int resultCnt = 1000; int afford = 1; List<ShopInfo> foodShops = client.getRecFoodShop(lng, lat, resultCnt, afford); System.out.println();// w ww . j a v a2s. c o m System.out.println(); List<ShopInfo> amuseShops = client.getRecAmuseShop(lng, lat, resultCnt, afford); System.out.println(); System.out.println(); List<ShopInfo> hotelShops = client.getRecHotelShop(lng, lat, resultCnt, afford); long beginTime = System.currentTimeMillis() - 10 * TimeUtil.ONE_HOUR; long endTime = beginTime + 25 * TimeUtil.ONE_HOUR + new Random().nextInt(500000); ShopInfoListBean bean = new ShopInfoListBean(beginTime, endTime, hotelShops, foodShops, amuseShops); RecommendEngine engine = new RecommendEngine(); RecmdResult result = engine.getRecmdResult(bean); System.out.println("Final Result:\n" + result); }
From source file:Main.java
public static ByteArrayInputStream getRandomDataStream(int length) { final Random randGenerator = new Random(); final byte[] buff = new byte[length]; randGenerator.nextBytes(buff);/* w w w .jav a2s .c o m*/ return new ByteArrayInputStream(buff); }
From source file:Main.java
private static Object getRandomValue(Class<?> type) { if (type.isAssignableFrom(Double.class)) { return new Random().nextDouble(); }//w w w .java 2s .c om if (type.isAssignableFrom(Short.class)) { return (short) new Random().nextInt(); } if (type.isAssignableFrom(Long.class)) { return new Random().nextLong(); } if (type.isAssignableFrom(Integer.class)) { return new Random().nextInt(); } if (type.isAssignableFrom(String.class)) { return "" + new Random().nextInt(); } if (type.isAssignableFrom(Boolean.class)) { return new Random().nextBoolean(); } if (type.isAssignableFrom(Date.class)) { return new Date(new Random().nextLong()); } if (type.isAssignableFrom(List.class)) { Class<?> listType = (Class<?>) ((ParameterizedType) type.getClass().getGenericSuperclass()) .getActualTypeArguments()[0]; return getRandomCollection(listType); } return null; }
From source file:Main.java
static File make_tmpdir(Context context, SQLiteDatabase db) throws Exception { File extdir = Environment.getExternalStorageDirectory(); File tmp_top = new File(extdir, "tmp_LongText"); if (!tmp_top.exists()) { if (!tmp_top.mkdir()) throw new Exception("cannot create directory: " + tmp_top.getPath()); }//from w w w . ja v a 2 s . co m if (!tmp_top.canWrite()) throw new Exception("missing permission to write to " + tmp_top.getPath()); File tmpdir; Random r = new Random(); do { tmpdir = new File(tmp_top, String.format("%d", r.nextInt())); } while (tmpdir.exists()); if (!tmpdir.mkdir()) throw new Exception("cannot create directory: " + tmp_top.getPath()); if (!tmpdir.canWrite()) throw new Exception("missing permission to write to " + tmp_top.getPath()); ContentValues v = new ContentValues(); v.put("pid", Process.myPid()); v.put("tmpdir", tmpdir.getPath()); v.put("ctime", System.currentTimeMillis()); db.insert("tmpdir", null, v); return tmpdir; }