List of usage examples for java.util Random nextInt
public int nextInt()
From source file:org.brekka.stillingar.example.PropertyPlaceholdersTest.java
private static Configuration writeConfig() { Random r = new Random(); ConfigurationDocument doc = ConfigurationDocument.Factory.newInstance(); configuration = doc.addNewConfiguration(); Testing testing = configuration.addNewTesting(); configuration.setMOTD("Value_" + RandomStringUtils.randomAlphabetic(6)); testing.setInt(r.nextInt()); testing.setString("${//c:MOTD}-${//c:Testing/c:Int}"); ThirdPartyConfiguration thirdPartyConfiguration = configuration.addNewThirdPartyConfiguration(); thirdPartyConfiguration.setHost("localhost"); thirdPartyConfiguration.setPort(1234); thirdPartyConfiguration.setUsername("username"); thirdPartyConfiguration.setPassword("password"); TestSupport.write(doc);// ww w .j a va 2s. co m return configuration; }
From source file:com.monitor.baseservice.utils.XCodeUtil.java
public static String createPrefix(int prefixLength) { Random random = new Random(); StringBuffer sb = new StringBuffer(); for (int i = 0; i < prefixLength; i++) { int tmp = random.nextInt(); if (tmp < 0) { tmp = -tmp;// w ww . j a va 2 s. c om } int index = tmp % digits.length(); sb.append(digits.charAt(index)); } return sb.toString(); }
From source file:Main.java
/** * Generates a random word./* w w w . jav a 2s . c o m*/ */ public static String generateWord(final Random random, final int[] codePointSet) { StringBuilder builder = new StringBuilder(); // 8 * 4 = 32 chars max, but we do it the following way so as to bias the random toward // longer words. This should be closer to natural language, and more importantly, it will // exercise the algorithms in dicttool much more. final int count = 1 + (Math.abs(random.nextInt()) % 5) + (Math.abs(random.nextInt()) % 5) + (Math.abs(random.nextInt()) % 5) + (Math.abs(random.nextInt()) % 5) + (Math.abs(random.nextInt()) % 5) + (Math.abs(random.nextInt()) % 5) + (Math.abs(random.nextInt()) % 5) + (Math.abs(random.nextInt()) % 5); while (builder.length() < count) { builder.appendCodePoint(codePointSet[Math.abs(random.nextInt()) % codePointSet.length]); } return builder.toString(); }
From source file:de.bund.bfr.knime.pmm.common.math.MathUtilities.java
public static int generateID(int seed) { Random rand = new Random(seed); int id = rand.nextInt(); if (id > 0) { id = -id;//from w w w . ja v a2s .c om } return id; }
From source file:de.hub.cs.dbis.aeolus.queries.utils.TimestampMergerTest.java
@BeforeClass public static void prepareStatic() { long seed = System.currentTimeMillis(); Random r = new Random(seed); System.out.println("Static test seed: " + seed); tsIndex = r.nextInt(); if (tsIndex < 0) { tsIndex *= -1;// w ww . ja v a2s . c om } duplicates = r.nextBoolean(); boltMockStatic = mock(IRichBolt.class); when(boltMockStatic.getComponentConfiguration()).thenReturn(boltConfig); checker = new TimestampOrderChecker(boltMockStatic, tsIndex, duplicates); }
From source file:com.linkedin.pinot.core.segment.index.creator.RawIndexCreatorTest.java
/** * Helper method that generates a random value for a given data type * * @param dataType Data type for which to generate the random value * @return Random value for the data type. *//* w w w.ja v a 2s . c o m*/ public static Object getRandomValue(Random random, FieldSpec.DataType dataType) { Object value; switch (dataType) { case INT: value = random.nextInt(); break; case LONG: value = random.nextLong(); break; case FLOAT: value = random.nextFloat(); break; case DOUBLE: value = random.nextDouble(); break; case STRING: value = StringUtil .trimTrailingNulls(RandomStringUtils.random(random.nextInt(MAX_STRING_LENGTH_IN_BYTES))); break; default: throw new IllegalArgumentException("Illegal data type for random value generator: " + dataType); } return value; }
From source file:Main.java
/** * Generates a random word.//from w ww .j ava2 s . c om */ @Nonnull public static String generateWord(@Nonnull final Random random, @Nonnull final int[] codePointSet) { final StringBuilder builder = new StringBuilder(); // 8 * 4 = 32 chars max, but we do it the following way so as to bias the random toward // longer words. This should be closer to natural language, and more importantly, it will // exercise the algorithms in dicttool much more. final int count = 1 + (Math.abs(random.nextInt()) % 5) + (Math.abs(random.nextInt()) % 5) + (Math.abs(random.nextInt()) % 5) + (Math.abs(random.nextInt()) % 5) + (Math.abs(random.nextInt()) % 5) + (Math.abs(random.nextInt()) % 5) + (Math.abs(random.nextInt()) % 5) + (Math.abs(random.nextInt()) % 5); while (builder.length() < count) { builder.appendCodePoint(codePointSet[Math.abs(random.nextInt()) % codePointSet.length]); } return builder.toString(); }
From source file:UnixCrypt.java
public static final String crypt(String original) { Random randomGenerator = new Random(); int numSaltChars = saltChars.length; String salt = "" + saltChars[Math.abs(randomGenerator.nextInt()) % numSaltChars] + saltChars[Math.abs(randomGenerator.nextInt()) % numSaltChars]; return crypt(salt, original); }
From source file:de.hub.cs.dbis.aeolus.utils.TimestampMergerTest.java
@BeforeClass public static void prepareStatic() { // final long seed = System.currentTimeMillis(); final long seed = 1432597577997L; Random r = new Random(seed); System.out.println("Static test seed: " + seed); tsIndex = r.nextInt(); if (tsIndex < 0) { tsIndex *= -1;/*w w w .j a va 2s . co m*/ } duplicates = r.nextBoolean(); boltMockStatic = mock(IRichBolt.class); when(boltMockStatic.getComponentConfiguration()).thenReturn(boltConfig); checker = new TimestampOrderChecker(boltMockStatic, tsIndex, duplicates); }
From source file:com.ikanow.aleph2.analytics.storm.utils.TestStormControllerUtil_Cache.java
private static File createFakeZipFile(String file_name) throws IOException { File file;/* w ww .j a va 2s . c om*/ if (file_name == null) file = File.createTempFile("recent_date_test_", ".zip"); else file = new File(file_name); Random r = new Random(); ZipOutputStream outputZip = new ZipOutputStream(new FileOutputStream(file)); ZipEntry e = new ZipEntry("some_file.tmp"); outputZip.putNextEntry(e); outputZip.write(r.nextInt()); outputZip.close(); return file; }