List of usage examples for java.util Random nextInt
public int nextInt(int bound)
From source file:io.cortical.retina.model.TestDataHarness.java
/** * Create dummy {@link Fingerprint}./*from ww w .ja v a 2 s. co m*/ * * @return dummy fingerprint. */ public static Fingerprint createFingerprint() { Random random = new Random(SEED); Set<Integer> positionSet = new LinkedHashSet<>(); while (positionSet.size() <= FINGERPRINT_LENGTH) { positionSet.add(random.nextInt(MAX_POSITION)); } Integer[] positionsInteger = new Integer[FINGERPRINT_LENGTH]; positionsInteger = positionSet.toArray(positionsInteger); sort(positionsInteger); return new Fingerprint(ArrayUtils.toPrimitive(positionsInteger)); }
From source file:OrdenacaoGUI.java
private static void fillRandom(int[] valores) { Random rand = new Random(); for (int i = 0; i < valores.length; i++) { valores[i] = rand.nextInt(valores.length); }//w w w. j a va2 s . co m }
From source file:justdailscrapper.vik.utility.FetchPageWithoutProxy.java
public static String fetchPageSourcefromClientGoogleSecond(URI newurl, List<ProxyImport> proxyList) throws IOException { Random r = new Random(); ProxyImport obj = proxyList.get(r.nextInt(proxyList.size())); String ip = obj.proxyIP;//from w ww . j a va 2 s. co m int portno = Integer.parseInt(obj.proxyPort); String username = ""; String password = ""; if (obj.proxyLen > 2) { username = obj.proxyUserName; password = obj.proxyPassword; } // int portNo = generateRandomPort(); CredentialsProvider credsprovider = new BasicCredentialsProvider(); credsprovider.setCredentials(new AuthScope(ip, portno), new UsernamePasswordCredentials(username, password)); HttpHost proxy = new HttpHost(ip, portno); //----------------------------------------------------------------------- RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(5000).setConnectTimeout(5000) .setConnectionRequestTimeout(5000).build(); CloseableHttpClient httpclient = HttpClients.custom().setDefaultCredentialsProvider(credsprovider) .setUserAgent("Mozilla/5.0 (Windows NT 6.1; WOW64; rv:35.0) Gecko/20100101 Firefox/35.0") .setDefaultRequestConfig(requestConfig).setProxy(proxy).build(); String responsebody = ""; String responsestatus = null; try { HttpGet httpget = new HttpGet(newurl); httpget.addHeader("Accept", "*/*"); httpget.addHeader("Accept-Encoding", "gzip, deflate, br"); httpget.addHeader("Accept-Language", "en-US,en;q=0.5"); httpget.addHeader("Host", "www.justdial.com"); httpget.addHeader("Referer", "https://www.justdial.com/Bangalore/Yamaha-Two-Wheeler-Dealers"); httpget.addHeader("Connection", "keep-alive"); httpget.addHeader("X-Requested-With", "XMLHttpReques"); System.out.println("Response status" + httpget.getRequestLine()); CloseableHttpResponse resp = httpclient.execute(httpget); responsestatus = resp.getStatusLine().toString(); if (responsestatus.contains("503") || responsestatus.contains("502") || responsestatus.contains("400") || responsestatus.contains("401") || responsestatus.contains("402") || responsestatus.contains("403") || responsestatus.contains("407") || responsestatus.contains("404") || responsestatus.contains("405") || responsestatus.contains("SSLHandshakeException") || responsestatus.contains("999") || responsestatus.contains("ClientProtocolException") || responsestatus.contains("SocketTimeoutException") || responsestatus == null || "".equals(responsestatus)) { return null; } else { HttpEntity entity = resp.getEntity(); System.out.println(resp.getStatusLine()); if (entity != null) { // System.out.println("Response content length: " + entity.getContentLength()); BufferedReader in = new BufferedReader(new InputStreamReader(entity.getContent())); String inputLine; while ((inputLine = in.readLine()) != null) { responsebody = new StringBuilder().append(responsebody).append(inputLine).toString(); } } EntityUtils.consume(entity); } } catch (IOException | IllegalStateException e) { return null; } finally { httpclient.close(); } return responsebody; }
From source file:ai.susi.server.AbstractAPIHandler.java
/** * Creates a random alphanumeric string//from ww w .j av a 2s. co m * @param length * @return */ public static String createRandomString(Integer length) { char[] chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789".toCharArray(); StringBuilder sb = new StringBuilder(); Random random = new Random(); for (int i = 0; i < length; i++) { char c = chars[random.nextInt(chars.length)]; sb.append(c); } return sb.toString(); }
From source file:controllers.user.UserApp.java
/** * ??/*from www . ja v a2s . co m*/ */ private static void arrangeService(User currentUser) { List<Expert> expertList = Expert.queryCustomerServices("\"?\"", true); Random r = new Random(); if (CollectionUtils.isEmpty(expertList)) { // ?? expertList = Expert.queryCustomerServices("\"?\"", null); } if (CollectionUtils.isNotEmpty(expertList)) { int i = r.nextInt(expertList.size()); Expert expert = expertList.get(i); // ??? Logger.info("?? ----> ?id" + expert.userId + "id" + currentUser.getId() + "???" + expert.userName + "??" + currentUser.getName()); String content = ""; MCMessageUtil.pustTxtMessage(currentUser.getId(), expert.userId, currentUser.getName(), expert.userName == null ? "" : expert.userName, content); MCMessageUtil.pustTxtMessage(currentUser.getId(), expert.userId, currentUser.getName(), expert.userName == null ? "" : expert.userName, ""); } }
From source file:com.enderville.enderinstaller.util.InstallScript.java
/** * Attempts to create a temporary directory in the installer folder to * unpack the jar.//from w w w . ja va 2s . c om * * @return * @throws IOException */ private static File getTempDir() throws IOException { Random rand = new Random(); String hex = Integer.toHexString(rand.nextInt(Integer.MAX_VALUE)); File tmp = new File(FilenameUtils.concat(InstallerConfig.getInstallerDir(), hex + "/")); int t = 0; while (tmp.exists() && t < 10) { hex = Integer.toHexString(rand.nextInt(Integer.MAX_VALUE)); tmp = new File(FilenameUtils.normalize("./" + hex + "/")); t++; } if (tmp.exists()) { throw new IOException("Error creating temporary folder. Too many failures."); } return tmp; }
From source file:edu.macalester.tagrelatedness.KendallsCorrelation.java
public static BigInteger getRandomBigInteger(int nDigits) { StringBuffer sb = new StringBuffer(); java.util.Random r = new java.util.Random(); for (int i = 0; i < nDigits; i++) { sb.append(r.nextInt(10)); }/* w ww .j a v a 2 s . c o m*/ return new BigInteger(sb.toString()); }
From source file:ecplugins.s3.TestUtils.java
public static int randInt() { int min = 100; int max = 10000; // NOTE: Usually this should be a field rather than a method // variable so that it is not re-seeded every call. Random rand = new Random(); // nextInt is normally exclusive of the top value, // so add 1 to make it inclusive int randomNum = rand.nextInt((max - min) + 1) + min; return randomNum; }
From source file:io.cortical.retina.model.TestDataHarness.java
/** * Create dummy {@link Fingerprint}.// w ww . java 2 s . co m * @param sparsity percentage of on bits * @return dummy fingerprint. */ public static Fingerprint createFingerprint(double sparsity) { Random random = new Random(SEED); Set<Integer> positionSet = new LinkedHashSet<>(); while (positionSet.size() <= ((double) (MAX_POSITION)) * sparsity) { positionSet.add(random.nextInt(MAX_POSITION)); } Integer[] positionsInteger = new Integer[FINGERPRINT_LENGTH]; positionsInteger = positionSet.toArray(positionsInteger); sort(positionsInteger); return new Fingerprint(ArrayUtils.toPrimitive(positionsInteger)); }
From source file:com.geekandroid.sdk.pay.impl.CHWeiXinPay.java
private static String genNonceStr() { Random random = new Random(); return MD5.getMessageDigest(String.valueOf(random.nextInt(10000)).getBytes()); }