Skip to content

Commit 02cbabf

Browse files
committed
Add a better random number generator
1 parent 931dfec commit 02cbabf

File tree

2 files changed

+15
-13
lines changed

2 files changed

+15
-13
lines changed

build.gradle

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,12 @@ plugins {
22
id 'java'
33
}
44

5+
//noinspection GroovyUnusedAssignment
6+
sourceCompatibility = targetCompatibility = JavaVersion.VERSION_1_8
7+
compileJava.options.encoding 'UTF-8'
8+
59
group 'me.dkim19375'
6-
version '2.3.2'
10+
version '2.3.3'
711

812
repositories {
913
mavenCentral()
Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,17 @@
11
package me.dkim19375.dkim19375core;
22

3+
import java.util.Random;
4+
35
public class NumberUtils {
4-
public static long getPercentage(long lower, long max) {
5-
return (lower * 100) / max;
6-
}
6+
private final static Random random = new Random();
7+
8+
public static long getPercentage(long lower, long max) { return (lower * 100) / max; }
9+
10+
public static double getPercentageDouble(double lower, double max) { return (lower * 100) / max; }
711

8-
public static double getPercentageDouble(double lower, double max) {
9-
return (lower * 100) / max;
10-
}
12+
public static boolean percentChance(float chance) { return Math.random() * 100 <= chance; }
1113

12-
public static boolean percentChance(float chance) {
13-
return Math.random() * 100 <= chance;
14-
}
14+
public static boolean percentChance(int chance) { return Math.random() * 100 <= chance; }
1515

16-
public static boolean percentChance(int chance) {
17-
return Math.random() * 100 <= chance;
18-
}
16+
public static int getRandomNumber(int minimum, int maximum) { return random.nextInt(maximum - minimum + 1) + maximum; }
1917
}

0 commit comments

Comments
 (0)