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:
parent
290ea11739
commit
538537dfd0
1 changed files with 5 additions and 1 deletions
|
@ -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);
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue