]> git.saurik.com Git - apple/javascriptcore.git/blobdiff - wtf/RandomNumberSeed.h
JavaScriptCore-621.1.tar.gz
[apple/javascriptcore.git] / wtf / RandomNumberSeed.h
index f994fd9e35c50e0d89d37c2ba691df08495510d5..ae414c0e32a7f5f395138935fe26f496c9039613 100644 (file)
 #include <sys/time.h>
 #endif
 
-#if PLATFORM(UNIX)
+#if OS(UNIX)
 #include <sys/types.h>
 #include <unistd.h>
 #endif
 
+#if OS(WINCE)
+extern "C" {
+void init_by_array(unsigned long init_key[],int key_length);
+}
+#endif
+
 // Internal JavaScriptCore usage only
 namespace WTF {
 
 inline void initializeRandomNumberGenerator()
 {
-#if PLATFORM(DARWIN)
+#if OS(DARWIN)
     // On Darwin we use arc4random which initialises itself.
+#elif OS(WINCE)
+    // initialize rand()
+    srand(static_cast<unsigned>(time(0)));
+
+    // use rand() to initialize the real RNG
+    unsigned long initializationBuffer[4];
+    initializationBuffer[0] = (rand() << 16) | rand();
+    initializationBuffer[1] = (rand() << 16) | rand();
+    initializationBuffer[2] = (rand() << 16) | rand();
+    initializationBuffer[3] = (rand() << 16) | rand();
+    init_by_array(initializationBuffer, 4);
 #elif COMPILER(MSVC) && defined(_CRT_RAND_S)
-    // On Windows we use rand_s which intialises itself
-#elif PLATFORM(UNIX)
+    // On Windows we use rand_s which initialises itself
+#elif OS(UNIX)
     // srandomdev is not guaranteed to exist on linux so we use this poor seed, this should be improved
     timeval time;
     gettimeofday(&time, 0);