Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.Marneus.Bot.API.Methods;
- import java.awt.Color;
- import java.util.Random;
- /**
- * A Random class that provides more efficient utilities than java.util.Random.
- *
- * @author MooseElkingtons
- */
- public class Rand {
- /**
- * Generates a random integer within the given range.
- *
- * @param min minimum amount it can generate.
- * @param max maximum amount it can generate.
- */
- public static int randomInt(int min, int max) {
- return min + new Random().nextInt(max - min);
- }
- /**
- * Generates a random String using alphanumeric characters.
- *
- * @param length the length of the String.
- */
- public static String randomString(int length) {
- String[] a = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',
- 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '1', '2', '3',
- '4', '5', '6', '7', '8', '9', '0'};
- StringBuilder sb = new StringBuilder("");
- Random random = new Random();
- for(int l = 0; l < length; l++) {
- sb.append(random.nextBoolean() ? a[random.nextInt(a.length)].toUpperCase() :
- a[random.nextInt(a.length)].toLowerCase());
- }
- return new String(sb);
- }
- /**
- * Generates a random color.
- *
- */
- public static Color randomColor() {
- Random random = new Random();
- return new Color(random.nextInt(255), random.nextInt(255), random.nextInt(255));
- }
- }
Add Comment
Please, Sign In to add comment