aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/apache/commons/lang3/RandomStringUtils.java
diff options
context:
space:
mode:
authorCaleb Cushing <xenoterracide@gmail.com>2015-06-28 02:06:27 -0500
committerpascalschumacher <pascalschumacher@gmx.net>2016-08-21 14:01:04 +0200
commitec2fa6bd5695b36435cc66ca4cdd8183d077a0cf (patch)
treeed0ba5f69428f0bec7623bbfda00a027ed5096c1 /src/main/java/org/apache/commons/lang3/RandomStringUtils.java
parent1169aac7a1a7bc056c37369892f638e137bff3e8 (diff)
downloadapache-commons-lang-ec2fa6bd5695b36435cc66ca4cdd8183d077a0cf.tar.gz
LANG-1224: Extend RandomStringUtils with methods that generate strings between a min and max length (closes #101, closes #157)
Diffstat (limited to 'src/main/java/org/apache/commons/lang3/RandomStringUtils.java')
-rw-r--r--src/main/java/org/apache/commons/lang3/RandomStringUtils.java93
1 files changed, 89 insertions, 4 deletions
diff --git a/src/main/java/org/apache/commons/lang3/RandomStringUtils.java b/src/main/java/org/apache/commons/lang3/RandomStringUtils.java
index 3db461f1a..fdcf87f68 100644
--- a/src/main/java/org/apache/commons/lang3/RandomStringUtils.java
+++ b/src/main/java/org/apache/commons/lang3/RandomStringUtils.java
@@ -81,7 +81,22 @@ public class RandomStringUtils {
public static String randomAscii(final int count) {
return random(count, 32, 127, false, false);
}
-
+
+ /**
+ * <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
+ */
+ public static String randomAscii(final int minLengthInclusive, final int maxLengthExclusive) {
+ return randomAscii(RandomUtils.nextInt(minLengthInclusive, maxLengthExclusive));
+ }
+
/**
* <p>Creates a random string whose length is the number of characters
* specified.</p>
@@ -95,7 +110,21 @@ public class RandomStringUtils {
public static String randomAlphabetic(final int count) {
return random(count, true, false);
}
-
+
+ /**
+ * <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 alphabetic 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
+ */
+ public static String randomAlphabetic(final int minLengthInclusive, final int maxLengthExclusive) {
+ return randomAlphabetic(RandomUtils.nextInt(minLengthInclusive, maxLengthExclusive));
+ }
+
/**
* <p>Creates a random string whose length is the number of characters
* specified.</p>
@@ -109,7 +138,21 @@ public class RandomStringUtils {
public static String randomAlphanumeric(final int count) {
return random(count, true, true);
}
-
+
+ /**
+ * <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 alpha-numeric 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
+ */
+ public static String randomAlphanumeric(final int minLengthInclusive, final int maxLengthExclusive) {
+ return randomAlphanumeric(RandomUtils.nextInt(minLengthInclusive, maxLengthExclusive));
+ }
+
/**
* <p>Creates a random string whose length is the number of characters specified.</p>
*
@@ -124,7 +167,21 @@ public class RandomStringUtils {
public static String randomGraph(final int count) {
return random(count, 33, 126, false, false);
}
-
+
+ /**
+ * <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
+ */
+ public static String randomGraph(final int minLengthInclusive, final int maxLengthExclusive) {
+ return randomGraph(RandomUtils.nextInt(minLengthInclusive, maxLengthExclusive));
+ }
+
/**
* <p>Creates a random string whose length is the number of characters
* specified.</p>
@@ -140,6 +197,20 @@ public class RandomStringUtils {
}
/**
+ * <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
+ */
+ public static String randomNumeric(final int minLengthInclusive, final int maxLengthExclusive) {
+ return randomNumeric(RandomUtils.nextInt(minLengthInclusive, maxLengthExclusive));
+ }
+
+ /**
* <p>Creates a random string whose length is the number of characters specified.</p>
*
* <p>Characters will be chosen from the set of characters which match the POSIX [:print:]
@@ -155,6 +226,20 @@ public class RandomStringUtils {
}
/**
+ * <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
+ */
+ public static String randomPrint(final int minLengthInclusive, final int maxLengthExclusive) {
+ return randomPrint(RandomUtils.nextInt(minLengthInclusive, maxLengthExclusive));
+ }
+
+ /**
* <p>Creates a random string whose length is the number of characters
* specified.</p>
*