All Downloads are FREE. Search and download functionalities are using the official Maven repository.

devutility.internal.util.RandomUtils Maven / Gradle / Ivy

There is a newer version: 1.3.8.1
Show newest version
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