mirror of
https://github.com/Eaglercraft-TeaVM-Fork/eagler-teavm.git
synced 2024-12-22 08:14:09 -08:00
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:
parent
6de4560282
commit
1964235fef
|
@ -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,19 +61,9 @@ 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:
|
||||
* centered around 0 with a standard deviation of 1.0.
|
||||
|
@ -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();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user