diff options
author | Andreas Kling <kling@serenityos.org> | 2020-03-23 13:14:04 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-03-23 13:14:04 +0100 |
commit | 538537dfd0d7db2288224ab384b24def7efe878e (patch) | |
tree | 9f04fc4ddcf203f795248f714e49e41416adf8ad /Libraries | |
parent | 290ea11739a52e63a3bcf45f9596fb29a60d4f48 (diff) | |
download | serenity-538537dfd0d7db2288224ab384b24def7efe878e.zip |
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.
Diffstat (limited to 'Libraries')
-rw-r--r-- | Libraries/LibJS/Runtime/MathObject.cpp | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/Libraries/LibJS/Runtime/MathObject.cpp b/Libraries/LibJS/Runtime/MathObject.cpp index 4c2e3764fb..076715b91a 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 <AK/Function.h> #include <AK/FlyString.h> +#include <AK/Function.h> #include <LibJS/Runtime/MathObject.h> namespace JS { @@ -33,7 +33,11 @@ namespace JS { MathObject::MathObject() { put_native_function("random", [](Object*, const Vector<Value>&) { +#ifdef __serenity__ double r = (double)arc4random() / (double)UINT32_MAX; +#else + double r = (double)rand() / (double)RAND_MAX; +#endif return Value(r); }); } |