mirror of
https://github.com/Eaglercraft-TeaVM-Fork/eagler-teavm.git
synced 2024-12-22 16:14:10 -08:00
Add Random next origin, bound methods for float, double, int and long (#609)
This commit is contained in:
parent
89f41b9a35
commit
f7f99b3c9f
|
@ -74,10 +74,18 @@ public class TRandom extends TObject implements TSerializable {
|
||||||
return (int) (nextDouble() * n);
|
return (int) (nextDouble() * n);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int nextInt(int origin, int bound) {
|
||||||
|
return origin + nextInt() * (bound - origin);
|
||||||
|
}
|
||||||
|
|
||||||
public long nextLong() {
|
public long nextLong() {
|
||||||
return ((long) nextInt() << 32) | nextInt();
|
return ((long) nextInt() << 32) | nextInt();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public long nextLong(long origin, long bound) {
|
||||||
|
return origin + nextLong() * (bound - origin);
|
||||||
|
}
|
||||||
|
|
||||||
public boolean nextBoolean() {
|
public boolean nextBoolean() {
|
||||||
return nextInt() % 2 == 0;
|
return nextInt() % 2 == 0;
|
||||||
}
|
}
|
||||||
|
@ -86,6 +94,10 @@ public class TRandom extends TObject implements TSerializable {
|
||||||
return (float) nextDouble();
|
return (float) nextDouble();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public float nextFloat(float origin, float bound) {
|
||||||
|
return origin + nextFloat() * (bound - origin);
|
||||||
|
}
|
||||||
|
|
||||||
public double nextDouble() {
|
public double nextDouble() {
|
||||||
if (PlatformDetector.isC()) {
|
if (PlatformDetector.isC()) {
|
||||||
return crand();
|
return crand();
|
||||||
|
@ -94,6 +106,10 @@ public class TRandom extends TObject implements TSerializable {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public double nextDouble(double origin, double bound) {
|
||||||
|
return origin + nextDouble() * (bound - origin);
|
||||||
|
}
|
||||||
|
|
||||||
@Import(name = "teavm_rand")
|
@Import(name = "teavm_rand")
|
||||||
@Unmanaged
|
@Unmanaged
|
||||||
private static native double crand();
|
private static native double crand();
|
||||||
|
|
Loading…
Reference in New Issue
Block a user