Guest User

Untitled

a guest
Dec 9th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 KB | None | 0 0
  1. package com.Marneus.Bot.API.Methods;
  2.  
  3. import java.awt.Color;
  4. import java.util.Random;
  5.  
  6. /**
  7. * A Random class that provides more efficient utilities than java.util.Random.
  8. *
  9. * @author MooseElkingtons
  10. */
  11.  
  12. public class Rand {
  13.  
  14.  
  15. /**
  16. * Generates a random integer within the given range.
  17. *
  18. * @param min minimum amount it can generate.
  19. * @param max maximum amount it can generate.
  20. */
  21. public static int randomInt(int min, int max) {
  22. return min + new Random().nextInt(max - min);
  23. }
  24.  
  25. /**
  26. * Generates a random String using alphanumeric characters.
  27. *
  28. * @param length the length of the String.
  29. */
  30. public static String randomString(int length) {
  31. String[] a = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',
  32. 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '1', '2', '3',
  33. '4', '5', '6', '7', '8', '9', '0'};
  34. StringBuilder sb = new StringBuilder("");
  35. Random random = new Random();
  36. for(int l = 0; l < length; l++) {
  37. sb.append(random.nextBoolean() ? a[random.nextInt(a.length)].toUpperCase() :
  38. a[random.nextInt(a.length)].toLowerCase());
  39. }
  40. return new String(sb);
  41. }
  42.  
  43. /**
  44. * Generates a random color.
  45. *
  46. */
  47. public static Color randomColor() {
  48. Random random = new Random();
  49. return new Color(random.nextInt(255), random.nextInt(255), random.nextInt(255));
  50. }
  51. }
Add Comment
Please, Sign In to add comment