/** * <p>Creates a random string whose length is the number of characters * specified.</p> * * <p>Characters will be chosen from the set of all characters.</p> * * @param count the length of random string to create * @return the random string */ public static String random(int count) { return random(count, false, false); }
/** * <p>Creates a random string whose length is the number of characters * specified.</p> * * <p>Characters will be chosen from the set of characters whose * ASCII value is between <code>32</code> and <code>126</code> (inclusive).</p> * * @param count the length of random string to create * @return the random string */ public static String randomAscii(int count) { return random(count, 32, 127, false, false); }
/** * <p>Creates a random string whose length is the number of characters * specified.</p> * * <p>Characters will be chosen from the set of alphabetic * characters.</p> * * @param count the length of random string to create * @return the random string */ public static String randomAlphabetic(int count) { return random(count, true, false); }
/** * <p>Creates a random string whose length is the number of characters * specified.</p> * * <p>Characters will be chosen from the set of alpha-numeric * characters.</p> * * @param count the length of random string to create * @return the random string */ public static String randomAlphanumeric(int count) { return random(count, true, true); }
/** * <p>Creates a random string whose length is the number of characters * specified.</p> * * <p>Characters will be chosen from the set of numeric * characters.</p> * * @param count the length of random string to create * @return the random string */ public static String randomNumeric(int count) { return random(count, false, true); }
/** * <p>Creates a random string whose length is the number of characters * specified.</p> * * <p>Characters will be chosen from the set of alpha-numeric * characters as indicated by the arguments.</p> * * @param count the length of random string to create * @param letters if <code>true</code>, generated string will include * alphabetic characters * @param numbers if <code>true</code>, generated string will include * numeric characters * @return the random string */ public static String random(int count, boolean letters, boolean numbers) { return random(count, 0, 0, letters, numbers); }
/** * <p>Creates a random string whose length is the number of characters * specified.</p> * * <p>Characters will be chosen from the set of characters specified.</p> * * @param count the length of random string to create * @param chars the character array containing the set of characters to use, * may be null * @return the random string * @throws IllegalArgumentException if <code>count</code> < 0. */ public static String random(int count, char[] chars) { if (chars == null) { return random(count, 0, 0, false, false, null, RANDOM); } return random(count, 0, chars.length, false, false, chars, RANDOM); }
/** * <p>Creates a random string whose length is the number of characters * specified.</p> * * <p>Characters will be chosen from the set of alpha-numeric * characters as indicated by the arguments.</p> * * @param count the length of random string to create * @param start the position in set of chars to start at * @param end the position in set of chars to end before * @param letters if <code>true</code>, generated string will include * alphabetic characters * @param numbers if <code>true</code>, generated string will include * numeric characters * @return the random string */ public static String random(int count, int start, int end, boolean letters, boolean numbers) { return random(count, start, end, letters, numbers, null, RANDOM); }
/** * <p>Creates a random string whose length is the number of characters * specified.</p> * * <p>Characters will be chosen from the set of characters * specified.</p> * * @param count the length of random string to create * @param chars the String containing the set of characters to use, * may be null * @return the random string * @throws IllegalArgumentException if <code>count</code> < 0. */ public static String random(int count, String chars) { if (chars == null) { return random(count, 0, 0, false, false, null, RANDOM); } return random(count, chars.toCharArray()); }
private static ArrayList<String> genStringList(int strLen, int count) { ArrayList<String> result = new ArrayList<String>(count); for (int i = 0; i < count; i++) { result.add(RandomStringUtils.random(strLen)); } return result; }
@Setup public void setUp() { Random random = new Random(123456789012345L); this.elements = new String[this.size]; for (int i = 0; i < this.size; i++) { this.elements[i] = RandomStringUtils.random(RANDOM_COUNT, 0, 0, false, true, null, random); } }
@Setup public void setUp() { Random random = new Random(123456789012345L); this.elements = new String[this.size]; for (int i = 0; i < this.size; i++) { this.elements[i] = RandomStringUtils.random(RANDOM_COUNT, 0, 0, false, true, null, random); } }
@Setup public void setUp() { this.elements = new String[this.size]; Random random = new Random(123456789012345L); for (int i = 0; i < this.size; i++) { this.elements[i] = RandomStringUtils.random(RANDOM_COUNT, 0, 0, false, true, null, random); } }
public static void fillRandom(String[] randomValues, int maxStringLength) { for (int i = 0; i < randomValues.length; i++) { randomValues[i] = RandomStringUtils.random(maxStringLength); } } }
private static File touch(File dir, String filename) throws IOException { File file = new File(dir, filename); FileUtils.write(file, RandomStringUtils.random(10)); return file; }
private List<String> getRandomRow() { row.clear(); for (int i = 0; i < ROW_LENGTH; i++) { row.add(RandomStringUtils.random(10)); } return row; } }
private List<String> getRandomRow() { List<String> row = new ArrayList<>(); for (int i = 0; i < ROW_LENGTH; i++) { row.add(RandomStringUtils.random(10)); } return row; }
FileAndMd5() throws IOException { this.file = temp.newFile(); FileUtils.write(this.file, RandomStringUtils.random(3)); try (InputStream fis = FileUtils.openInputStream(this.file)) { this.md5 = DigestUtils.md5Hex(fis); } catch (IOException e) { throw new IllegalStateException("Fail to compute md5 of " + this.file, e); } }
@Test public void testString() { for (int i = 0; i < NUM_ITERATIONS; i++) { String expected = RandomStringUtils.random(RANDOM.nextInt(20)); byte[] bytes = ObjectSerDeUtils.serialize(expected); String actual = ObjectSerDeUtils.deserialize(bytes, ObjectSerDeUtils.ObjectType.String); assertEquals(actual, expected, ERROR_MESSAGE); } }
private void testStringDictionary(ImmutableDictionaryReader stringDictionary) { for (int i = 0; i < NUM_VALUES; i++) { assertEquals(stringDictionary.get(i), _stringValues[i]); assertEquals(stringDictionary.getStringValue(i), _stringValues[i]); assertEquals(stringDictionary.indexOf(_stringValues[i]), i); // Test String longer than MAX_STRING_LENGTH String randomString = RandomStringUtils.random(RANDOM.nextInt(2 * MAX_STRING_LENGTH)).replace('\0', ' '); assertEquals(stringDictionary.insertionIndexOf(randomString), Arrays.binarySearch(_stringValues, randomString)); } }