Ignore:
Timestamp:
Jan 27, 2010, 6:07:59 AM (15 years ago)
Author:
[email protected]
Message:

2010-01-27 Kwang Yul Seo <[email protected]>

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):
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/wtf/RandomNumber.cpp

    r52791 r53928  
    4141#endif
    4242
     43#if PLATFORM(BREWMP)
     44#include <AEEAppGen.h>
     45#include <AEESource.h>
     46#include <AEEStdLib.h>
     47#endif
     48
    4349namespace WTF {
    4450
     
    4854    // rand_s is incredibly slow on windows so we fall back on rand for Math.random
    4955    return (rand() + (rand() / (RAND_MAX + 1.0))) / (RAND_MAX + 1.0);
     56#elif PLATFORM(BREWMP)
     57    uint32_t bits;
     58    GETRAND(reinterpret_cast<byte*>(&bits), sizeof(uint32_t));
     59    return static_cast<double>(bits) / (static_cast<double>(std::numeric_limits<uint32_t>::max()) + 1.0);
    5060#else
    5161    return randomNumber();
     
    100110    fullRandom &= (1LL << 53) - 1;
    101111    return static_cast<double>(fullRandom)/static_cast<double>(1LL << 53);
     112#elif PLATFORM(BREWMP)
     113    uint32_t bits;
     114    ISource* randomSource;
     115
     116    IShell* shell = reinterpret_cast<AEEApplet*>(GETAPPINSTANCE())->m_pIShell;
     117    ISHELL_CreateInstance(shell, AEECLSID_RANDOM, reinterpret_cast<void**>(&randomSource));
     118    ISOURCE_Read(randomSource, reinterpret_cast<char*>(&bits), 4);
     119    ISOURCE_Release(randomSource);
     120
     121    return static_cast<double>(bits) / (static_cast<double>(std::numeric_limits<uint32_t>::max()) + 1.0);
    102122#else
    103123    uint32_t part1 = rand() & (RAND_MAX - 1);
Note: See TracChangeset for help on using the changeset viewer.