List of usage examples for java.util Random nextInt
public int nextInt()
From source file:Main.java
/** Returns a random integer between 0 and n-1 */ public static int nextInt(int n) { Random rand = new Random(seed); return Math.abs(rand.nextInt()) % n; }
From source file:Main.java
private static String getOutTradeNo() { SimpleDateFormat format = new SimpleDateFormat("MMddHHmmss", Locale.getDefault()); Date date = new Date(); String key = format.format(date); Random r = new Random(); key = key + r.nextInt(); key = key.substring(0, 15);//from ww w .java2 s.c om return key; }
From source file:Main.java
public static String getRandomColor() { Random rand = new Random(); Integer randomColor = Color.rgb(rand.nextInt(), rand.nextInt(), rand.nextInt()); return randomColor.toString(); }
From source file:Main.java
public static int getRandom() { Random ran = new Random(System.currentTimeMillis()); int ret = ran.nextInt(); ret = Math.abs(ret);/* ww w . j a v a 2s . com*/ return ret; }
From source file:Main.java
public static String getRandomFileName(String filePath) { SimpleDateFormat format = new SimpleDateFormat("MMddHHmmss", Locale.getDefault()); Date date = new Date(); String key = format.format(date); Random r = new Random(); key = key + r.nextInt(); key = key.substring(0, 15);// w ww .j a v a2 s .c o m return filePath + "/" + key + ".jpeg"; }
From source file:Main.java
public static int generateRandomColour(long seed) { Random random = new Random(seed); int color = Color.argb(random.nextInt(), random.nextInt(), random.nextInt(), random.nextInt()); float[] hsv = new float[3]; Color.colorToHSV(color, hsv); //Adjust the saturation value, less than 1 is darker, greater than 1 is brighter hsv[2] *= 0.8;/* ww w. j a va 2s .c o m*/ return Color.HSVToColor(hsv); }
From source file:Main.java
/** * @param min// ww w . j a v a 2 s .co m * @param max * @return */ public static String getYZM(final int min, final int max) { Random random = new Random(); int randomnum = 0; int tmp = Math.abs(random.nextInt()); randomnum = tmp % (max - min + 1) + min; return randomnum + ""; }
From source file:Main.java
private static void printPassword() { String UPPER = "ABCDEFGHIJKLMNPQRSTUVWXYZ"; String LOWER = "abcdefghijklmnpqrstuvwxyz"; String NUMBER = "123456789"; String SPECIAL = "!@#$%&*+?"; Random randGen = new Random(); StringBuffer buf = new StringBuffer(); buf.append(LOWER.charAt(Math.abs(randGen.nextInt()) % LOWER.length())); buf.append(LOWER.charAt(Math.abs(randGen.nextInt()) % LOWER.length())); buf.append(NUMBER.charAt(Math.abs(randGen.nextInt()) % NUMBER.length())); for (int i = 0; i <= 4; i++) { buf.append(LOWER.charAt(Math.abs(randGen.nextInt()) % LOWER.length())); }/*from w ww.j a v a 2 s . c o m*/ buf.append(UPPER.charAt(Math.abs(randGen.nextInt()) % UPPER.length())); buf.append(LOWER.charAt(Math.abs(randGen.nextInt()) % LOWER.length())); System.out.println(buf.toString()); }
From source file:Main.java
public static String generateString(int length) { StringBuffer sb = new StringBuffer(); Random random = new Random(); for (int i = 0; i < length; i++) { sb.append(random.nextInt()); }/* ww w. j av a2s. c om*/ return sb.toString(); }
From source file:MainClass.java
private static void fillArray(Object array) { int length = Array.getLength(array); Random generator = new Random(System.currentTimeMillis()); for (int i = 0; i < length; i++) { int random = generator.nextInt(); Array.setInt(array, i, random); }//from ww w . j av a2 s . c o m }