From 538537dfd0d7db2288224ab384b24def7efe878e Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Mon, 23 Mar 2020 13:14:04 +0100 Subject: [PATCH] LibJS: Use rand() for Math.random() on other systems I bet we could be smarter here and use arc4random() on systems where it is present. I'm not sure how to detect it though. --- Libraries/LibJS/Runtime/MathObject.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Libraries/LibJS/Runtime/MathObject.cpp b/Libraries/LibJS/Runtime/MathObject.cpp index 4c2e3764fb5..076715b91ad 100644 --- a/Libraries/LibJS/Runtime/MathObject.cpp +++ b/Libraries/LibJS/Runtime/MathObject.cpp @@ -24,8 +24,8 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include #include +#include #include namespace JS { @@ -33,7 +33,11 @@ namespace JS { MathObject::MathObject() { put_native_function("random", [](Object*, const Vector&) { +#ifdef __serenity__ double r = (double)arc4random() / (double)UINT32_MAX; +#else + double r = (double)rand() / (double)RAND_MAX; +#endif return Value(r); }); }