diff --git a/classlib/src/main/java/org/teavm/classlib/java/util/TRandom.java b/classlib/src/main/java/org/teavm/classlib/java/util/TRandom.java index f72bbfbe2..30157cdae 100644 --- a/classlib/src/main/java/org/teavm/classlib/java/util/TRandom.java +++ b/classlib/src/main/java/org/teavm/classlib/java/util/TRandom.java @@ -74,10 +74,18 @@ public class TRandom extends TObject implements TSerializable { return (int) (nextDouble() * n); } + public int nextInt(int origin, int bound) { + return origin + nextInt() * (bound - origin); + } + public long nextLong() { return ((long) nextInt() << 32) | nextInt(); } + public long nextLong(long origin, long bound) { + return origin + nextLong() * (bound - origin); + } + public boolean nextBoolean() { return nextInt() % 2 == 0; } @@ -86,6 +94,10 @@ public class TRandom extends TObject implements TSerializable { return (float) nextDouble(); } + public float nextFloat(float origin, float bound) { + return origin + nextFloat() * (bound - origin); + } + public double nextDouble() { if (PlatformDetector.isC()) { 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") @Unmanaged private static native double crand();