List of usage examples for java.util Collections shuffle
public static void shuffle(List<?> list)
From source file:com.shirokumacafe.archetype.common.utilities.RandomData.java
/** * list?n.//from www.j av a 2s. c o m */ public static <T> List<T> randomSome(List<T> list, int n) { Collections.shuffle(list); return list.subList(0, n); }
From source file:com.ijuru.ijambo.Utils.java
/** * Scrambles the letters of a word. Shuffles the word twice and returns * the result with the highest levenshtein distance from the original * @param word the word//from w ww. j a v a2 s.c om * @return the scrambled word */ public static String scrambleWord(String word) { List<String> chars1 = Arrays.asList(word.split("")); List<String> chars2 = new ArrayList<String>(chars1); Collections.shuffle(chars1); Collections.shuffle(chars2); String scramble1 = StringUtils.join(chars1, ""); String scramble2 = StringUtils.join(chars2, ""); int dist1 = StringUtils.getLevenshteinDistance(word, scramble1); int dist2 = StringUtils.getLevenshteinDistance(word, scramble2); return (dist1 > dist2) ? scramble1 : scramble2; }
From source file:Main.java
/** * This method generates a random n digit password, which contains at least one number, lower case alphabet, upper * case alphabet and as special character. *//*from w ww .j a v a 2s . c om*/ public static String generatePassword(int n) { Random rd = new Random(); char lowerChars[] = "abcdefghijklmnopqrstuvwxyz".toCharArray(); char upperChars[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".toCharArray(); char numbers[] = "0123456789".toCharArray(); char specialChars[] = "~!@#$%^&*()-_=+[{]}|;:<>/?".toCharArray(); List<Character> pwdLst = new ArrayList<Character>(); for (int g = 0; g < 4; g++) { for (int z = 0; z < 1; z++) { if (g == 0) { pwdLst.add(numbers[rd.nextInt(10)]); } else if (g == 1) { pwdLst.add(lowerChars[rd.nextInt(26)]); } else if (g == 2) { pwdLst.add(upperChars[rd.nextInt(26)]); } else if (g == 3) { pwdLst.add(specialChars[rd.nextInt(26)]); } } if (pwdLst.size() == n) { break; } if (g + 1 == 4) { g = (int) Math.random() * 5; } } StringBuilder password = new StringBuilder(); Collections.shuffle(pwdLst); for (int c = 0; c < pwdLst.size(); c++) { password.append(pwdLst.get(c)); } return password.toString(); }
From source file:com.dianping.dpsf.other.echo.SimpleEchoClient.java
private static List<String[]> generateHostList() { List<String[]> hostList = new ArrayList<String[]>(); hostList.add(new String[] { "127.0.0.1", "20001" }); hostList.add(new String[] { "127.0.0.1", "20002" }); hostList.add(new String[] { "127.0.0.1", "20003" }); Random rnd = new Random(System.currentTimeMillis()); int num = rnd.nextInt(3) + 1; Collections.shuffle(hostList); return hostList.subList(0, num); }
From source file:com.stb.async.EncodedSTBProcesses.java
/** * * @param range/*from w ww . j a v a 2s. com*/ * @param total_processes * @return */ public List initiateProcess(int total_processes, int range) { ArrayList<Integer> numbers = new ArrayList<>(); for (int i = 0; i < range; i++) { numbers.add(i + 1); } Collections.shuffle(numbers); for (int j = 0; j < total_processes; j++) { System.out.print(numbers.get(j) + " "); procList.add(new Process("Process P" + numbers.get(j) + " .", numbers.get(j))); } return procList; }
From source file:edu.eci.arsw.blindway.mazegenerator.RecursiveMazeGenerator.java
private void generateMaze(int cx, int cy) { DIR[] dirs = DIR.values();/*from www . j av a 2s . c o m*/ Collections.shuffle(Arrays.asList(dirs)); for (DIR dir : dirs) { int nx = cx + dir.dx; int ny = cy + dir.dy; if (between(nx, x) && between(ny, y) && (maze[nx][ny] == 0)) { maze[cx][cy] |= dir.bit; maze[nx][ny] |= dir.opposite.bit; generateMaze(nx, ny); } } }
From source file:edu.isi.pfindr.learn.util.PairsFileIO.java
@SuppressWarnings("unchecked") public static void shuffler(String pairsFilename) throws IOException { List<String> fileWithPairs = FileUtils.readLines(new File(pairsFilename)); Collections.shuffle(fileWithPairs); String outputFilename = pairsFilename.split("\\.")[0] + "_s.txt"; //output filename derived from the pairs filename FileUtils.writeLines(new File(outputFilename), fileWithPairs); }
From source file:Main.java
public RandomIterator(final Iterator<T> i) { final List<T> items; items = new ArrayList<T>(); while (i.hasNext()) { final T item; item = i.next();/*from ww w.j a va 2 s . c om*/ items.add(item); } Collections.shuffle(items); iterator = items.iterator(); }
From source file:com.joyent.manta.client.MantaObjectDepthComparatorTest.java
public void verifyOrderingWithSmallDataSet() { List<MantaObject> objects = new ArrayList<>(); List<MantaObject> dirs = dirObjects(12); for (MantaObject dir : dirs) { objects.add(dir);//from w w w.j ava 2 s . c o m objects.addAll(fileObjects(dir, 3)); } Collections.shuffle(objects); objects.sort(MantaObjectDepthComparator.INSTANCE); assertOrdering(objects); }
From source file:common.Utilities.java
public static List<Integer> getRandomIndices(int from, int to) { List<Integer> indices = new ArrayList<Integer>(); for (int j = from; j <= to; j++) { indices.add(j);/*w ww . j a va2 s .c o m*/ } Collections.shuffle(indices); return indices; }