classlib: directly use Math.random() in Random

Math.random() already handles the implementation for the backends,
delegating to JavaScript's Math.random() or the C runtime
implementation.

Fixes duplicate symbols when using the WASM backend.
This commit is contained in:
Bernd Busse 2024-01-05 14:17:55 +01:00 committed by Alexey Andreev
parent 6de4560282
commit 1964235fef

View File

@ -15,15 +15,10 @@
*/
package org.teavm.classlib.java.util;
import org.teavm.backend.wasm.runtime.WasmSupport;
import org.teavm.classlib.PlatformDetector;
import org.teavm.classlib.impl.RandomUtils;
import org.teavm.classlib.java.io.TSerializable;
import org.teavm.classlib.java.lang.TObject;
import org.teavm.classlib.java.util.random.TRandomGenerator;
import org.teavm.interop.Import;
import org.teavm.interop.Unmanaged;
import org.teavm.jso.JSBody;
public class TRandom extends TObject implements TRandomGenerator, TSerializable {
/** A stored gaussian value for nextGaussian() */
@ -66,18 +61,8 @@ public class TRandom extends TObject implements TRandomGenerator, TSerializable
@Override
public double nextDouble() {
if (PlatformDetector.isC()) {
return crand();
} else if (PlatformDetector.isWebAssembly()) {
return WasmSupport.random();
} else {
return random();
return Math.random();
}
}
@Import(name = "teavm_rand")
@Unmanaged
private static native double crand();
/**
* Generate a random number with Gaussian distribution:
@ -101,9 +86,4 @@ public class TRandom extends TObject implements TRandomGenerator, TSerializable
return pair[0];
}
@JSBody(script = "return Math.random();")
@Import(module = "teavmMath", name = "random")
@Unmanaged
private static native double random();
}