summaryrefslogtreecommitdiffstats
path: root/JavaScriptCore/wtf/RandomNumber.cpp
diff options
context:
space:
mode:
authorSteve Block <steveblock@google.com>2010-02-02 14:57:50 +0000
committerSteve Block <steveblock@google.com>2010-02-04 15:06:55 +0000
commitd0825bca7fe65beaee391d30da42e937db621564 (patch)
tree7461c49eb5844ffd1f35d1ba2c8b7584c1620823 /JavaScriptCore/wtf/RandomNumber.cpp
parent3db770bd97c5a59b6c7574ca80a39e5a51c1defd (diff)
downloadexternal_webkit-d0825bca7fe65beaee391d30da42e937db621564.zip
external_webkit-d0825bca7fe65beaee391d30da42e937db621564.tar.gz
external_webkit-d0825bca7fe65beaee391d30da42e937db621564.tar.bz2
Merge webkit.org at r54127 : Initial merge by git
Change-Id: Ib661abb595522f50ea406f72d3a0ce17f7193c82
Diffstat (limited to 'JavaScriptCore/wtf/RandomNumber.cpp')
-rw-r--r--JavaScriptCore/wtf/RandomNumber.cpp30
1 files changed, 25 insertions, 5 deletions
diff --git a/JavaScriptCore/wtf/RandomNumber.cpp b/JavaScriptCore/wtf/RandomNumber.cpp
index 52fb130..fc48263 100644
--- a/JavaScriptCore/wtf/RandomNumber.cpp
+++ b/JavaScriptCore/wtf/RandomNumber.cpp
@@ -34,12 +34,18 @@
#include <stdint.h>
#include <stdlib.h>
-#if PLATFORM(WINCE)
+#if OS(WINCE)
extern "C" {
#include "wince/mt19937ar.c"
}
#endif
+#if PLATFORM(BREWMP)
+#include <AEEAppGen.h>
+#include <AEESource.h>
+#include <AEEStdLib.h>
+#endif
+
namespace WTF {
double weakRandomNumber()
@@ -47,6 +53,10 @@ double weakRandomNumber()
#if COMPILER(MSVC) && defined(_CRT_RAND_S)
// rand_s is incredibly slow on windows so we fall back on rand for Math.random
return (rand() + (rand() / (RAND_MAX + 1.0))) / (RAND_MAX + 1.0);
+#elif PLATFORM(BREWMP)
+ uint32_t bits;
+ GETRAND(reinterpret_cast<byte*>(&bits), sizeof(uint32_t));
+ return static_cast<double>(bits) / (static_cast<double>(std::numeric_limits<uint32_t>::max()) + 1.0);
#else
return randomNumber();
#endif
@@ -66,10 +76,10 @@ double randomNumber()
uint32_t bits;
rand_s(&bits);
return static_cast<double>(bits) / (static_cast<double>(std::numeric_limits<uint32_t>::max()) + 1.0);
-#elif PLATFORM(DARWIN)
+#elif OS(DARWIN)
uint32_t bits = arc4random();
return static_cast<double>(bits) / (static_cast<double>(std::numeric_limits<uint32_t>::max()) + 1.0);
-#elif PLATFORM(UNIX)
+#elif OS(UNIX)
uint32_t part1 = random() & (RAND_MAX - 1);
uint32_t part2 = random() & (RAND_MAX - 1);
// random only provides 31 bits
@@ -80,9 +90,9 @@ double randomNumber()
// Mask off the low 53bits
fullRandom &= (1LL << 53) - 1;
return static_cast<double>(fullRandom)/static_cast<double>(1LL << 53);
-#elif PLATFORM(WINCE)
+#elif OS(WINCE)
return genrand_res53();
-#elif PLATFORM(WIN_OS)
+#elif OS(WINDOWS)
uint32_t part1 = rand() & (RAND_MAX - 1);
uint32_t part2 = rand() & (RAND_MAX - 1);
uint32_t part3 = rand() & (RAND_MAX - 1);
@@ -99,6 +109,16 @@ double randomNumber()
// Mask off the low 53bits
fullRandom &= (1LL << 53) - 1;
return static_cast<double>(fullRandom)/static_cast<double>(1LL << 53);
+#elif PLATFORM(BREWMP)
+ uint32_t bits;
+ ISource* randomSource;
+
+ IShell* shell = reinterpret_cast<AEEApplet*>(GETAPPINSTANCE())->m_pIShell;
+ ISHELL_CreateInstance(shell, AEECLSID_RANDOM, reinterpret_cast<void**>(&randomSource));
+ ISOURCE_Read(randomSource, reinterpret_cast<char*>(&bits), 4);
+ ISOURCE_Release(randomSource);
+
+ return static_cast<double>(bits) / (static_cast<double>(std::numeric_limits<uint32_t>::max()) + 1.0);
#else
uint32_t part1 = rand() & (RAND_MAX - 1);
uint32_t part2 = rand() & (RAND_MAX - 1);