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) {
|
||||
if (n <= 0) {
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
return (int) (nextDouble() * n);
|
||||
}
|
||||
|
||||
|
|
|
@ -15,9 +15,9 @@
|
|||
*/
|
||||
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 TThreadLocalRandom() {
|
||||
|
@ -37,8 +37,8 @@ public class TThreadLocalRandom extends Random {
|
|||
throw new IllegalArgumentException();
|
||||
}
|
||||
int range = bound - origin;
|
||||
if (range < 0) {
|
||||
return nextInt(bound - origin) + origin;
|
||||
if (range > 0) {
|
||||
return nextInt(range) + origin;
|
||||
} else {
|
||||
while (true) {
|
||||
int value = nextInt();
|
||||
|
@ -67,8 +67,8 @@ public class TThreadLocalRandom extends Random {
|
|||
throw new IllegalArgumentException();
|
||||
}
|
||||
long range = bound - origin;
|
||||
if (range < 0) {
|
||||
return nextLong(bound - origin) + origin;
|
||||
if (range > 0) {
|
||||
return nextLong(range) + origin;
|
||||
} else {
|
||||
while (true) {
|
||||
long value = nextLong();
|
||||
|
|
Loading…
Reference in New Issue
Block a user