/** * <p> Returns a random int within 0 - Integer.MAX_VALUE </p> * * @return the random integer * @see #nextInt(int, int) * @since 3.5 */ public static int nextInt() { return nextInt(0, Integer.MAX_VALUE); }
/** * <p>Creates a random string whose length is between the inclusive minimum and * the exclusive maximum.</p> * * <p>Characters will be chosen from the set of \p{Print} characters.</p> * * @param minLengthInclusive the inclusive minimum length of the string to generate * @param maxLengthExclusive the exclusive maximum length of the string to generate * @return the random string * @since 3.5 */ public static String randomPrint(final int minLengthInclusive, final int maxLengthExclusive) { return randomPrint(RandomUtils.nextInt(minLengthInclusive, maxLengthExclusive)); }
public static <T> T getRandomElement(List<T> list) { if (list.size() < 1) return null; return list.get(RandomUtils.nextInt(0, list.size())); }
/** * <p>Creates a random string whose length is between the inclusive minimum and * the exclusive maximum.</p> * * <p>Characters will be chosen from the set of Latin alphabetic characters (a-z, A-Z).</p> * * @param minLengthInclusive the inclusive minimum length of the string to generate * @param maxLengthExclusive the exclusive maximum length of the string to generate * @return the random string * @since 3.5 */ public static String randomAlphabetic(final int minLengthInclusive, final int maxLengthExclusive) { return randomAlphabetic(RandomUtils.nextInt(minLengthInclusive, maxLengthExclusive)); }
/** * <p>Creates a random string whose length is between the inclusive minimum and * the exclusive maximum.</p> * * <p>Characters will be chosen from the set of \p{Graph} characters.</p> * * @param minLengthInclusive the inclusive minimum length of the string to generate * @param maxLengthExclusive the exclusive maximum length of the string to generate * @return the random string * @since 3.5 */ public static String randomGraph(final int minLengthInclusive, final int maxLengthExclusive) { return randomGraph(RandomUtils.nextInt(minLengthInclusive, maxLengthExclusive)); }
/** * <p>Creates a random string whose length is between the inclusive minimum and * the exclusive maximum.</p> * * <p>Characters will be chosen from the set of \p{Digit} characters.</p> * * @param minLengthInclusive the inclusive minimum length of the string to generate * @param maxLengthExclusive the exclusive maximum length of the string to generate * @return the random string * @since 3.5 */ public static String randomNumeric(final int minLengthInclusive, final int maxLengthExclusive) { return randomNumeric(RandomUtils.nextInt(minLengthInclusive, maxLengthExclusive)); }
/** * <p>Creates a random string whose length is between the inclusive minimum and * the exclusive maximum.</p> * * <p>Characters will be chosen from the set of characters whose * ASCII value is between {@code 32} and {@code 126} (inclusive).</p> * * @param minLengthInclusive the inclusive minimum length of the string to generate * @param maxLengthExclusive the exclusive maximum length of the string to generate * @return the random string * @since 3.5 */ public static String randomAscii(final int minLengthInclusive, final int maxLengthExclusive) { return randomAscii(RandomUtils.nextInt(minLengthInclusive, maxLengthExclusive)); }
/** * <p>Creates a random string whose length is between the inclusive minimum and * the exclusive maximum.</p> * * <p>Characters will be chosen from the set of Latin alphabetic * characters (a-z, A-Z) and the digits 0-9.</p> * * @param minLengthInclusive the inclusive minimum length of the string to generate * @param maxLengthExclusive the exclusive maximum length of the string to generate * @return the random string * @since 3.5 */ public static String randomAlphanumeric(final int minLengthInclusive, final int maxLengthExclusive) { return randomAlphanumeric(RandomUtils.nextInt(minLengthInclusive, maxLengthExclusive)); }
public void initCheckRT() { // first check time delay checkRTNormalized = 2000 + RandomUtils.nextInt(0, Switch.getTcpHealthParams().getMax()); checkRTBest = Long.MAX_VALUE; checkRTWorst = 0L; }
@Test(expected = IllegalArgumentException.class) public void testNextIntNegative() throws Exception { RandomUtils.nextInt(-1, 1); }
@Test(expected = IllegalArgumentException.class) public void testNextIntLowerGreaterUpper() throws Exception { RandomUtils.nextInt(2, 1); }
private ColumnFamilyDescriptor createFamilyDesc() { String familyName = String.format("cf-%010d", RandomUtils.nextInt()); return ColumnFamilyDescriptorBuilder.of(familyName); } }
private NamespaceDescriptor createNamespaceDesc() { String namespaceName = "itnamespace" + String.format("%010d", RandomUtils.nextInt()); NamespaceDescriptor nsd = NamespaceDescriptor.create(namespaceName).build(); nsd.setConfiguration( nsTestConfigKey, String.format("%010d", RandomUtils.nextInt())); return nsd; } }
/** * Tests next int range. */ @Test public void testNextInt() { final int result = RandomUtils.nextInt(33, 42); assertTrue(result >= 33 && result < 42); }
/** * Test next int range with minimal range. */ @Test public void testNextIntMinimalRange() { assertEquals(42, RandomUtils.nextInt(42, 42)); }
/** * Tests extreme range. */ @Test public void testExtremeRangeInt() { final int result = RandomUtils.nextInt(0, Integer.MAX_VALUE); assertTrue(result >= 0 && result < Integer.MAX_VALUE); }
private TableDescriptor createTableDesc() { String tableName = String.format("ittable-%010d", RandomUtils.nextInt()); String familyName = "cf-" + Math.abs(RandomUtils.nextInt()); return TableDescriptorBuilder.newBuilder(TableName.valueOf(tableName)) .setColumnFamily(ColumnFamilyDescriptorBuilder.of(familyName)) .build(); } }
static void moveRegion(Admin admin, ServerName [] servers, RegionInfo regionInfo) { try { String destServerName = servers[RandomUtils.nextInt(0, servers.length)].getServerName(); LOG.debug("Moving {} to {}", regionInfo.getRegionNameAsString(), destServerName); admin.move(regionInfo.getEncodedNameAsBytes(), Bytes.toBytes(destServerName)); } catch (Exception ex) { LOG.warn("Move failed, might be caused by other chaos: {}", ex.getMessage()); } } }
/** * Tests next double range, random result. */ @Test public void testNextIntRandomResult() { final int randomResult = RandomUtils.nextInt(); assertTrue(randomResult > 0); assertTrue(randomResult < Integer.MAX_VALUE); }
@Override public void perform() throws Exception { LOG.info("Performing action: Restart random RS holding table " + this.locator.getName()); List<HRegionLocation> locations = locator.getAllRegionLocations(); restartRs(locations.get(RandomUtils.nextInt(0, locations.size())).getServerName(), sleepTime); } }