List of usage examples for java.util Random nextInt
public int nextInt(int bound)
From source file:com.sap.core.odata.testutil.helper.StringHelper.java
/** * Generates a string with given length containing random upper case characters ([A-Z]). * @param len length of the generated string * @return random upper case characters ([A-Z]) *//*from ww w. j av a 2s. c o m*/ public static String generateData(final int len) { Random random = new Random(); StringBuilder b = new StringBuilder(len); for (int j = 0; j < len; j++) { final char c = (char) ('A' + random.nextInt('Z' - 'A' + 1)); b.append(c); } return b.toString(); }
From source file:Main.java
/** * get random color rgb value// w w w. j ava2s. c om * @return rgb color int */ public static int getRandomColor() { Random random = new Random(); /* * Better limiting value. * if value is too small, it will appear lighter * if value is too large, it will appear darker */ //limit within 50-199 int red = random.nextInt(150) + 50; int green = random.nextInt(150) + 50; int blue = random.nextInt(150) + 50; //create a color int as per rgb and return return Color.rgb(red, green, blue); }
From source file:Main.java
public static String generatePassword() { Random r[] = new Random[8]; r[0] = new Random(); r[1] = new Random(); r[2] = new Random(); r[3] = new Random(); r[4] = new Random(); r[5] = new Random(); r[6] = new Random(); r[7] = new Random(); Random x = new Random(); StringBuilder password = new StringBuilder(); int length = 6; password.setLength(length);//from ww w . j a v a 2 s.c o m for (int i = 0; i < length; i++) { x.setSeed(r[i % 8].nextInt(500) * r[4].nextInt(900)); password.setCharAt(i, (char) (r[x.nextInt(256) % 8].nextInt(95) + 32)); } return password.toString(); }
From source file:com.microsoft.tfs.core.httpclient.methods.multipart.MultipartRequestEntity.java
/** * Generates a random multipart boundary string. * * @return/*w w w .j a va 2 s . co m*/ */ private static byte[] generateMultipartBoundary() { final Random rand = new Random(); final byte[] bytes = new byte[rand.nextInt(11) + 30]; // a random size // from 30 // to 40 for (int i = 0; i < bytes.length; i++) { bytes[i] = MULTIPART_CHARS[rand.nextInt(MULTIPART_CHARS.length)]; } return bytes; }
From source file:eu.falcon.fusion.TestTimeSeries.java
public static int randInt(int min, int max) { // Usually this can be a field rather than a method variable 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:com.android.internal.http.multipart.MultipartEntity.java
/** * Generates a random multipart boundary string. *//*w w w .j av a 2 s .c o m*/ private static byte[] generateMultipartBoundary() { Random rand = new Random(); byte[] bytes = new byte[rand.nextInt(11) + 30]; // a random size from 30 to 40 for (int i = 0; i < bytes.length; i++) { bytes[i] = MULTIPART_CHARS[rand.nextInt(MULTIPART_CHARS.length)]; } return bytes; }
From source file:com.linkedin.paldb.impl.GenerateTestData.java
public static Integer[] generateRandomIntKeys(int count, int range, long seed) { Random random = new Random(seed); Set<Integer> set = new HashSet<Integer>(count); while (set.size() < count) { set.add(random.nextInt(range)); }//from w ww. j a v a2 s.co m return set.toArray(new Integer[0]); }
From source file:it.cnr.isti.smartfed.test.DatacenterFacilities.java
public static List<FederationDatacenter> getUniformDistribution(int numOfDatacenters, int numOfHost, FederationDatacenterProfile profile) { Random r = new Random(13213); int core_variance = maxNumOfCores - minNumOfCores; int delta_cores = core_variance > 0 ? r.nextInt(core_variance) : 0; if (numOfHost < 1) numOfHost = 1;//from w ww. j ava 2 s. co m List<FederationDatacenter> list = new ArrayList<FederationDatacenter>(); for (int i = 0; i < numOfDatacenters; i++) { // create the virtual processor (PE) List<Pe> peList = new ArrayList<Pe>(); int mips = 25000; for (int j = 0; j < minNumOfCores + delta_cores; j++) { peList.add(new Pe(j, new PeProvisionerSimple(mips))); } // create the hosts List<Host> hostList = new ArrayList<Host>(); HostProfile prof = HostProfile.getDefault(); prof.set(HostParams.RAM_AMOUNT_MB, 16 * 1024 + ""); for (int k = 0; k < numOfHost; k++) { hostList.add(HostFactory.get(prof, peList)); } // create the storage List<Storage> storageList = new ArrayList<Storage>(); // if empty, no SAN attached // create the datacenters list.add(FederationDatacenterFactory.get(profile, hostList, storageList)); } return list; }
From source file:com.hisrv.lib.multipart.MultipartEntity.java
/** * Generates a random multipart boundary string. *///from www .j a v a 2 s . c om private static byte[] generateMultipartBoundary() { Random rand = new Random(); byte[] bytes = new byte[rand.nextInt(11) + 30]; // a random size from 30 // to 40 for (int i = 0; i < bytes.length; i++) { bytes[i] = MULTIPART_CHARS[rand.nextInt(MULTIPART_CHARS.length)]; } return bytes; }
From source file:com.cognifide.actions.msg.replication.ReplicationMessageProducer.java
private static String generateRandomPathPart(String randomPath) { final StringBuilder builder = new StringBuilder(); final Random random = new Random(); for (char c : randomPath.toCharArray()) { if (c == '*') { builder.append(Integer.toHexString(random.nextInt(16))); } else {//from ww w. j av a 2s . c om builder.append(c); } } return builder.toString(); }