Commit 260364fb authored by eric@webkit.org's avatar eric@webkit.org

2010-01-27 Kwang Yul Seo <skyul@company100.net>

        Reviewed by Eric Seidel.

        [BREWMP] Port WTF's randomNumber
        https://bugs.webkit.org/show_bug.cgi?id=33566

        Use GETRAND to generate 4 byte random byte sequence to implement
        weakRandomNumber. Create a secure random number generator with
        AEECLSID_RANDOM to implement randomNumber.

        * wtf/RandomNumber.cpp:
        (WTF::weakRandomNumber):
        (WTF::randomNumber):

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@53928 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 1d23c496
2010-01-27 Kwang Yul Seo <skyul@company100.net>
Reviewed by Eric Seidel.
[BREWMP] Port WTF's randomNumber
https://bugs.webkit.org/show_bug.cgi?id=33566
Use GETRAND to generate 4 byte random byte sequence to implement
weakRandomNumber. Create a secure random number generator with
AEECLSID_RANDOM to implement randomNumber.
* wtf/RandomNumber.cpp:
(WTF::weakRandomNumber):
(WTF::randomNumber):
2010-01-27 Kwang Yul Seo <skyul@company100.net>
Reviewed by Eric Seidel.
......
......@@ -40,6 +40,12 @@ extern "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
......@@ -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);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment