List of usage examples for java.util Random nextInt
public int nextInt(int bound)
From source file:Main.java
/** * Gets random string//w w w. ja v a2 s . co m * * @param length String length * @return Random string */ public static String getRandomString(int length) { char[] chars = "ABCDEFGHIJKLMONPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".toCharArray(); StringBuilder builder = new StringBuilder(); Random random = new Random(); for (int i = 0; i < length; i++) { char c = chars[random.nextInt(chars.length)]; builder.append(c); } return builder.toString(); }
From source file:Main.java
public static int[] getRandomArray(int length, int max) { int[] randArray = new int[length]; Random rand = new Random(); for (int i = 0; i < length; i++) { randArray[i] = rand.nextInt(max); }//from ww w . j a v a2s . co m Arrays.sort(randArray); for (int i = 1; i < length; i++) { if (randArray[i] == randArray[i - 1]) { randArray[i] += 1; } } for (int i = length - 1; i > 0; i--) { if (randArray[i] == randArray[i - 1]) { randArray[i - 1] -= 1; } } return randArray; }
From source file:alfio.util.PasswordGenerator.java
public static String generateRandomPassword() { if (DEV_MODE) { return "abcd"; }/* w w w. j av a 2 s. c o m*/ Random r = new Random(); int length = MIN_LENGTH + r.nextInt(MAX_LENGTH - MIN_LENGTH + 1); return RandomStringUtils.random(length, PASSWORD_CHARACTERS); }
From source file:Main.java
/** * @author TheMrMilchmann//w w w . ja v a 2s . c om * @since DerpieLang v1.0.0 */ public static final <T> T[] fillRandomly(T[] from, T[] into, long seed) { Random random = new Random(seed); for (int i = 0; i < into.length; i++) { into[i] = from[random.nextInt(from.length)]; } return into; }
From source file:Main.java
static int randomNumber(int first, int second) { Random r = new Random(); int bigger = Math.max(first, second); int smaller = Math.min(first, second); return r.nextInt(bigger - smaller + 1) + smaller; }
From source file:Main.java
public static String generateString(int length) { StringBuilder tmp = new StringBuilder(); for (char ch = '0'; ch <= '9'; ++ch) tmp.append(ch);/* w ww .jav a 2 s. c o m*/ for (char ch = 'a'; ch <= 'z'; ++ch) tmp.append(ch); char[] symbols = tmp.toString().toCharArray(); char[] buf = new char[length]; Random random = new Random(); for (int idx = 0; idx < buf.length; ++idx) buf[idx] = symbols[random.nextInt(symbols.length)]; return new String(buf); }
From source file:edu.buffalo.fusim.ExtractSeq.java
public static StringBuffer randomSequence(int maxLen) { Random r = new Random(); // Chose a random length int length = r.nextInt(maxLen) + 1; StringBuffer seq = new StringBuffer(); for (int i = 0; i < length; i++) { seq.append(bases[r.nextInt(bases.length)]); }//ww w. java2 s . c o m return seq; }
From source file:Main.java
public static int ramdomMinMax(int min, int max) { Random random = new Random(); int rs = -1;/*from w w w . j a v a 2s. com*/ while (rs < min || rs > max) { rs = random.nextInt(max); } return rs; }
From source file:GenerateWorkItems.java
private static Integer getRandomObjectIdFromList(List beanList) { Random generator = new Random(); int random = generator.nextInt(beanList.size()); return ((IBeanID) beanList.get(random)).getObjectID(); }
From source file:outfox.dict.contest.test.InitSingerData.java
public static String getRandomCity() { String[] arr = { "", "", "", "", "?", "" }; Random rand = new Random(); int index = rand.nextInt(arr.length); return arr[index]; }