List of usage examples for java.lang Math random
public static double random()
From source file:Main.java
@SuppressWarnings("unused") public static String getRandomNumber(int count) { Random rdm = new Random(System.currentTimeMillis()); String random = ""; for (int i = 0; i < count; i++) { String str = String.valueOf((int) (Math.random() * 10 - 1)); random = random + str;// w ww. j a va 2s .c om } return random; }
From source file:Main.java
public static String getRandomString(int len) { StringBuffer sb = new StringBuffer(len); for (int i = 0; i < len; i++) { int ndx = (int) (Math.random() * ALPHA_NUM.length()); sb.append(ALPHA_NUM.charAt(ndx)); }//ww w . j a v a 2 s . co m return sb.toString(); }
From source file:Main.java
/** * Generate a random message-id header for locally-generated messages. *///from w ww . j av a 2 s.c om public static String generateMessageId() { StringBuffer sb = new StringBuffer(); sb.append("<"); for (int i = 0; i < 24; i++) { sb.append(Integer.toString((int) (Math.random() * 35), 36)); } sb.append("."); sb.append(Long.toString(System.currentTimeMillis())); sb.append("@email.android.com>"); return sb.toString(); }
From source file:MainClass.java
public static int randomInt(int low, int high) { int result = (int) (Math.random() * (high - low + 1)) + low; return result; }
From source file:Main.java
public static int[] randomColor(int size) { int[] returncolors = new int[size]; for (int i = 0; i < size; i++) { returncolors[i] = colors[(int) (Math.random() * 6)]; }/*from ww w .ja va 2s .c o m*/ return returncolors; }
From source file:Main.java
/** Sleeps between floor and ceiling milliseconds, chosen randomly */ public static void sleepRandom(long floor, long ceiling) { if (ceiling - floor <= 0) { return;/*from www . j a va 2 s .co m*/ } long diff = ceiling - floor; long r = (int) ((Math.random() * 100000) % diff) + floor; sleep(r); }
From source file:Main.java
public static int roll() { return (int) Math.ceil(Math.random() * 6); }
From source file:Main.java
public static Date getRandomDate() { final long beginTime = Timestamp.valueOf("2017-01-13 00:00:00").getTime(); final long endTime = Timestamp.valueOf("2017-02-14 00:58:00").getTime(); long diff = endTime - beginTime + 1; long timeStamp = beginTime + (long) (Math.random() * diff); return new Date(timeStamp); }
From source file:Main.java
public static List<Double> populateDoubleList(int numberOfItems) { List<Double> dummyDoubleList = null; if (numberOfItems > 0) { dummyDoubleList = new ArrayList<Double>(); for (int i = 0; i < numberOfItems; i++) { final double randomNumber = (Math.random() * numberOfItems); dummyDoubleList.add(randomNumber); }/*from ww w . ja va 2 s. c om*/ } return dummyDoubleList; }
From source file:Main.java
public static String[] populateStringArray(int numberOfItems) { final String partialWord = "partialArrayParallel"; String[] dummyStringArray = null; if (numberOfItems > 0) { dummyStringArray = new String[numberOfItems]; for (int i = 0; i < numberOfItems; i++) { final double randomNumber = (Math.random() * numberOfItems); final StringBuilder sb = new StringBuilder(partialWord).append(randomNumber); dummyStringArray[i] = sb.toString(); }// w ww. ja v a 2 s. c o m } return dummyStringArray; }