List of usage examples for java.util Random Random
public Random()
From source file:dtu.ds.warnme.utils.RandomUtils.java
public static float randomBearing() { float[] values = new float[] { 0f, 90f, 180f, 270f }; int idx = new Random().nextInt(values.length); return values[idx]; }
From source file:com.eventsourcing.hlc.NTPServerTimeProviderTest.java
@DataProvider(name = "delays", parallel = true) public static Iterator<Object[]> delays() { return IntStream.generate(() -> new Random().nextInt(3000)) .limit(ForkJoinPool.getCommonPoolParallelism() * 10).boxed().map(i -> new Object[] { i }) .collect(Collectors.toList()).iterator(); }
From source file:com.skilrock.lms.common.utility.AutoGenerate.java
public static String autoPassword() { Random r = new Random(); StringBuffer newString = new StringBuffer(); // No of Big letters in password int a1 = r.nextInt(6) + 1; // No of small letters in password int a2 = r.nextInt(7 - a1) + 1; // no on numbers int a3 = 8 - a1 - a2; for (int j = 0; j < a1; j++) { char c1 = (char) (r.nextInt(26) + 65); // AL.add(new Character(c1)); newString.append(new Character(c1)); }/*from ww w . j av a 2 s . co m*/ for (int j = 0; j < a2; j++) { char c1 = (char) (r.nextInt(26) + 97); // AL.add(new Character(c1)); newString.append(new Character(c1)); } for (int j = 0; j < a3; j++) { char c1 = (char) (r.nextInt(9) + 48); // AL.add(new Character(c1)); newString.append(new Character(c1)); } //logger.debug("pwd = " + newString.toString()); return newString.toString(); }
From source file:Main.java
/** * Using like subList() but it take randoms elements. * * @param list/*from w w w .j av a 2s .c om*/ * @param sizeOfSubList */ public static <E> void randomSubList(List<E> list, int sizeOfSubList) { List<E> subList = Collections.emptyList(); if (isNotEmpty(list) && list.size() > sizeOfSubList) { subList = new ArrayList<E>(sizeOfSubList); Random generator = new Random(); for (int i = 0; i < sizeOfSubList; i++) { int random = generator.nextInt(list.size()); subList.add(list.get(random)); list.remove(random); } } list.clear(); list.addAll(subList); }
From source file:com.tjtolley.roborally.game.BoardDefinition.java
public static BoardDefinition randomConfiguration(String name, int height, int width) { Random r = new Random(); List<List<Tile>> board = Lists.newArrayList(); Tile.TileType[] values = Tile.TileType.values(); final Direction[] dirValues = Direction.values(); for (int x = 0; x < width; x++) { final ArrayList<Tile> column = Lists.<Tile>newArrayList(); board.add(x, column);//from w w w .j a v a 2 s. co m for (int y = 0; y < height; y++) { int valIdx = r.nextInt(values.length); int dirIdx = r.nextInt(dirValues.length); column.add(y, new Tile(values[valIdx], x, y, dirValues[dirIdx], EdgeType.EMPTY, EdgeType.EMPTY, EdgeType.EMPTY, EdgeType.EMPTY)); } } return new BoardDefinition(name, board, width, height); }
From source file:fr.esecure.banking.metier.utils.PasswordGenerator.java
public static String genererDefaultPassword() { int n;/*from www . jav a 2s. c o m*/ String password = ""; Random r = new Random(); for (int i = 0; i < NChar; i++) { n = r.nextInt(4); // gnere un nombre alatoire entre 0 et 3 if (n == 0) password += maj[r.nextInt(maj.length)]; else if (n == 1) password += min[r.nextInt(min.length)]; else if (n == 2) password += chiffre[r.nextInt(chiffre.length)]; else password += charSpecial[r.nextInt(charSpecial.length)]; } return password; }
From source file:org.couchbase.mock.http.query.QueryServer.java
/** * This is the equivalent to 'dropping' indexes */ public static void resetIndexState() { randNumber = new Random().nextInt(); }
From source file:com.wabacus.util.FileLockTools.java
public static Object lock(String lockfile, int waitsec, int maxtimes) { Object lockresource = lock(lockfile); Random random = new Random(); int times = 0; while (lockresource == null) { if (times++ >= maxtimes) { log.debug("??" + lockfile + "?" + maxtimes + "?"); break; }//from w w w. ja v a2 s.co m try { Thread.sleep(random.nextInt(waitsec) * 1000); } catch (Exception e) { e.printStackTrace(); } lockresource = lock(lockfile); } return lockresource; }
From source file:Points.java
public void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2d = (Graphics2D) g; g2d.setColor(Color.red);/*from w w w .j a v a 2 s . c om*/ for (int i = 0; i <= 100000; i++) { Dimension size = getSize(); int w = size.width; int h = size.height; Random r = new Random(); int x = Math.abs(r.nextInt()) % w; int y = Math.abs(r.nextInt()) % h; g2d.drawLine(x, y, x, y); } }
From source file:ListOfCitys.CityList.java
public static JSONObject getCityNameForCountry(String countryName, String zipName) { List<String> cities = new ArrayList<>(); List<String> citiesList = new ArrayList<>(); JSONObject obj = new JSONObject(); try {/*from w ww . j av a 2 s .co m*/ WebService.setUserName("nane"); ToponymSearchCriteria searchCriteria = new ToponymSearchCriteria(); searchCriteria.setQ(countryName); ToponymSearchResult searchResult; searchResult = WebService.search(searchCriteria); for (int i = 0; i < searchResult.getToponyms().size(); ++i) { cities.add(searchResult.getToponyms().get(i).getName()); } for (int j = 0; j < 3; ++j) { citiesList.add(cities.get(new Random().nextInt(cities.size()))); } obj.put(zipName, citiesList.toArray()); return obj; } catch (Exception ex) { Logger.getLogger(CityList.class.getName()).log(Level.SEVERE, null, ex); } return obj; }