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 private RandomUtils() {
31 }
32
33
34
35
36
37
38 public static Boolean nextBoolean() {
39 return Boolean.valueOf(Math.random() > 0.5);
40 }
41
42
43
44
45
46
47 public static Byte nextByte() {
48 return Byte.valueOf(("" + Math.random() * Integer.MAX_VALUE).substring(0, 1));
49 }
50
51 public static Integer nextInteger() {
52 return Integer.valueOf((int) Math.random() * Integer.MAX_VALUE);
53 }
54
55
56
57
58
59
60 public static Character nextCharacter() {
61 int end = 'z' + 1;
62 int start = ' ';
63
64 StringBuilder buffer = new StringBuilder();
65 int gap = end - start;
66
67 buffer.append((char) ((int) (Math.random() * gap) + start));
68 return Character.valueOf((buffer.toString().charAt(0)));
69 }
70
71
72
73
74
75
76 public static String nextString(Integer length) {
77 int end = 'z' + 1;
78 int start = ' ';
79
80 StringBuilder buffer = new StringBuilder();
81 int gap = end - start;
82 for (int i = 0; i < length; i++) {
83 char ch = (char) ((int) (Math.random() * gap) + start);
84 if (Character.isLetter(ch)) {
85 buffer.append(ch);
86 } else {
87 i--;
88 }
89 }
90
91 return buffer.toString();
92 }
93
94 public static Long nextLong() {
95 return Long.valueOf((long) (Math.random() * Long.MAX_VALUE));
96 }
97
98 public static Date nextDate() {
99 long date = RandomUtils.nextLong();
100 long maxDate = new Date().getTime();
101 return new Date(date > maxDate ? maxDate : date);
102 }
103
104 public static Short nextShort() {
105 return Short.valueOf((short) (Math.random() * Short.MAX_VALUE));
106 }
107
108 public static Double nextDouble() {
109 return Double.valueOf((double) (Math.random() * Double.MAX_VALUE));
110 }
111 }