mirror of
https://github.com/Eaglercraft-TeaVM-Fork/eagler-teavm.git
synced 2024-12-22 08:14:09 -08:00
Fix issues in Random and ThreadLocalRandom (#536)
This commit is contained in:
parent
baeb2a28a7
commit
605628d6df
|
@ -68,6 +68,9 @@ public class TRandom extends TObject implements TSerializable {
|
||||||
}
|
}
|
||||||
|
|
||||||
public int nextInt(int n) {
|
public int nextInt(int n) {
|
||||||
|
if (n <= 0) {
|
||||||
|
throw new IllegalArgumentException();
|
||||||
|
}
|
||||||
return (int) (nextDouble() * n);
|
return (int) (nextDouble() * n);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -15,9 +15,9 @@
|
||||||
*/
|
*/
|
||||||
package org.teavm.classlib.java.util.concurrent;
|
package org.teavm.classlib.java.util.concurrent;
|
||||||
|
|
||||||
import java.util.Random;
|
import org.teavm.classlib.java.util.TRandom;
|
||||||
|
|
||||||
public class TThreadLocalRandom extends Random {
|
public class TThreadLocalRandom extends TRandom {
|
||||||
private static final TThreadLocalRandom current = new TThreadLocalRandom();
|
private static final TThreadLocalRandom current = new TThreadLocalRandom();
|
||||||
|
|
||||||
private TThreadLocalRandom() {
|
private TThreadLocalRandom() {
|
||||||
|
@ -37,8 +37,8 @@ public class TThreadLocalRandom extends Random {
|
||||||
throw new IllegalArgumentException();
|
throw new IllegalArgumentException();
|
||||||
}
|
}
|
||||||
int range = bound - origin;
|
int range = bound - origin;
|
||||||
if (range < 0) {
|
if (range > 0) {
|
||||||
return nextInt(bound - origin) + origin;
|
return nextInt(range) + origin;
|
||||||
} else {
|
} else {
|
||||||
while (true) {
|
while (true) {
|
||||||
int value = nextInt();
|
int value = nextInt();
|
||||||
|
@ -67,8 +67,8 @@ public class TThreadLocalRandom extends Random {
|
||||||
throw new IllegalArgumentException();
|
throw new IllegalArgumentException();
|
||||||
}
|
}
|
||||||
long range = bound - origin;
|
long range = bound - origin;
|
||||||
if (range < 0) {
|
if (range > 0) {
|
||||||
return nextLong(bound - origin) + origin;
|
return nextLong(range) + origin;
|
||||||
} else {
|
} else {
|
||||||
while (true) {
|
while (true) {
|
||||||
long value = nextLong();
|
long value = nextLong();
|
||||||
|
|
Loading…
Reference in New Issue
Block a user