devutility.internal.util.RandomUtils Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of devutility.internal Show documentation
Show all versions of devutility.internal Show documentation
Utilities for Java development
package devutility.internal.util;
import java.util.Random;
public class RandomUtils {
/**
* Random instance
*/
private static final Random RANDOM = new Random();
/**
* Get random string
* @param chars: Chars pool which will generate random string.
* @param length: Chars length
* @return String
*/
public static String getString(char[] chars, int length) {
StringBuffer buffer = new StringBuffer();
for (int i = 0; i < length; i++) {
buffer.append(chars[RANDOM.nextInt(chars.length)]);
}
return buffer.toString();
}
/**
* Get random number
* @param bound: Scope for random number.
* @return int
*/
public static int getNumber(int bound) {
return RANDOM.nextInt(bound);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy