| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | |
|
| 18 | |
|
| 19 | |
package org.org.usurper.utils; |
| 20 | |
|
| 21 | |
import java.util.Date; |
| 22 | |
|
| 23 | |
|
| 24 | |
|
| 25 | |
|
| 26 | |
|
| 27 | |
public class RandomUtils { |
| 28 | |
|
| 29 | |
@SuppressWarnings("unused") |
| 30 | 0 | private RandomUtils() { |
| 31 | 0 | } |
| 32 | |
|
| 33 | |
|
| 34 | |
|
| 35 | |
|
| 36 | |
|
| 37 | |
|
| 38 | |
public static Boolean nextBoolean() { |
| 39 | 767 | return Boolean.valueOf(Math.random() > 0.5); |
| 40 | |
} |
| 41 | |
|
| 42 | |
|
| 43 | |
|
| 44 | |
|
| 45 | |
|
| 46 | |
|
| 47 | |
public static Byte nextByte() { |
| 48 | 285 | return Byte.valueOf(("" + Math.random() * Integer.MAX_VALUE).substring(0, 1)); |
| 49 | |
} |
| 50 | |
|
| 51 | |
public static Integer nextInteger() { |
| 52 | 1663 | return Integer.valueOf((int) Math.random() * Integer.MAX_VALUE); |
| 53 | |
} |
| 54 | |
|
| 55 | |
|
| 56 | |
|
| 57 | |
|
| 58 | |
|
| 59 | |
|
| 60 | |
public static Character nextCharacter() { |
| 61 | 285 | int end = 'z' + 1; |
| 62 | 285 | int start = ' '; |
| 63 | |
|
| 64 | 285 | StringBuilder buffer = new StringBuilder(); |
| 65 | 285 | int gap = end - start; |
| 66 | |
|
| 67 | 285 | buffer.append((char) ((int) (Math.random() * gap) + start)); |
| 68 | 285 | return Character.valueOf((buffer.toString().charAt(0))); |
| 69 | |
} |
| 70 | |
|
| 71 | |
|
| 72 | |
|
| 73 | |
|
| 74 | |
|
| 75 | |
|
| 76 | |
public static String nextString(Integer length) { |
| 77 | 712 | int end = 'z' + 1; |
| 78 | 712 | int start = ' '; |
| 79 | |
|
| 80 | 712 | StringBuilder buffer = new StringBuilder(); |
| 81 | 712 | int gap = end - start; |
| 82 | 13258 | for (int i = 0; i < length; i++) { |
| 83 | 12546 | char ch = (char) ((int) (Math.random() * gap) + start); |
| 84 | 12546 | if (Character.isLetter(ch)) { |
| 85 | 7120 | buffer.append(ch); |
| 86 | |
} else { |
| 87 | 5426 | i--; |
| 88 | |
} |
| 89 | |
} |
| 90 | |
|
| 91 | 712 | return buffer.toString(); |
| 92 | |
} |
| 93 | |
|
| 94 | |
public static Long nextLong() { |
| 95 | 1668 | return Long.valueOf((long) (Math.random() * Long.MAX_VALUE)); |
| 96 | |
} |
| 97 | |
|
| 98 | |
public static Date nextDate() { |
| 99 | 904 | long date = RandomUtils.nextLong(); |
| 100 | 904 | long maxDate = new Date().getTime(); |
| 101 | 904 | return new Date(date > maxDate ? maxDate : date); |
| 102 | |
} |
| 103 | |
|
| 104 | |
public static Short nextShort() { |
| 105 | 764 | return Short.valueOf((short) (Math.random() * Short.MAX_VALUE)); |
| 106 | |
} |
| 107 | |
|
| 108 | |
public static Double nextDouble() { |
| 109 | 802 | return Double.valueOf((double) (Math.random() * Double.MAX_VALUE)); |
| 110 | |
} |
| 111 | |
} |