1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 08:38:12 +00:00

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.
This commit is contained in:
Andreas Kling 2020-03-23 13:14:04 +01:00
parent 290ea11739
commit 538537dfd0

View file

@ -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);
});
}