List of usage examples for java.lang Math random
public static double random()
From source file:Main.java
/** * Returns a random number between 0 and f. *///from ww w .j a v a2s .c om public static float random(float f) { return ((float) Math.random()) * f; }
From source file:Main.java
public static int getRndNum(int min, int max) { return (int) Math.round((max - min) * Math.random() + min); }
From source file:PrintWriterDemo.java
public static void main() throws Exception { PrintWriter pw = new PrintWriter(new FileWriter("dice.txt")); for (int i = 1; i <= 1000; i++) { int die = (int) (1 + 6 * Math.random()); pw.print(die);//from w ww . j a v a 2 s . c o m pw.print(' '); if (i % 20 == 0) pw.println(); } pw.println(); pw.close(); // Without this, the output file may be empty }
From source file:Main.java
public static int random(int max) { return (int) (Math.random() * max); }
From source file:Main.java
/** * Calculate experience based on minimum experience provided by enemy... * @param baseExperience/*from w ww . j av a 2 s .c om*/ * */ public static int getGold(int baseGold) { float random = (float) Math.random(); return (int) (baseGold + (baseGold * random)); }
From source file:Main.java
public static char[] getCheckChar(int textlength) { char[] tempCheckNum = new char[textlength]; for (int i = 0; i < textlength; i++) { char charCode; if (Math.random() > 0.5d) { charCode = (char) (Math.random() * 26 + 'A'); } else {//from ww w .j a va2s .com charCode = (char) (Math.random() * 10 + '0'); } tempCheckNum[i] = charCode; } return tempCheckNum; }
From source file:Main.java
public static int[] getLine(int width, int height) { int[] lineCoordinate = new int[4]; for (int i = 0; i < 4; i += 2) { lineCoordinate[i] = (int) (Math.random() * width); lineCoordinate[i + 1] = (int) (Math.random() * height); }//from w w w . j a va2s .com return lineCoordinate; }
From source file:TimerUtil.java
public final static void waitRandom(int time) { int waitTime = (int) (Math.random() * (double) time); try {//from w w w .j a v a 2 s.com Thread.sleep(waitTime); } catch (Exception e) { } }
From source file:Main.java
public static int randomInt(int low, int high) { return (int) (Math.random() * (high - low)) + low; }
From source file:Main.java
/** * Generated UID to anonymously identify users on GCM server. * @return/* ww w .j av a 2 s. c om*/ */ public static String generateUid() { return Long.toHexString(Double.doubleToLongBits(Math.random())); }