Created
August 24, 2012 05:58
-
-
Save MooseElkingtons/3446202 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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)); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment