Ignore:
Timestamp:
Oct 2, 2009, 4:35:31 PM (16 years ago)
Author:
[email protected]
Message:

2009-10-02 Jonni Rainisto <[email protected]>

Reviewed by Darin Adler.

Math.random() gives too low values on Win32 when _CRT_RAND_S is not defined
https://bugs.webkit.org/show_bug.cgi?id=29956

  • wtf/RandomNumber.cpp: (WTF::randomNumber): Added PLATFORM(WIN_OS) to handle 15bit rand()
File:
1 edited

Legend:

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

    r45865 r49056  
    8383#elif PLATFORM(WINCE)
    8484    return genrand_res53();
     85#elif PLATFORM(WIN_OS)
     86    uint32_t part1 = rand() & (RAND_MAX - 1);
     87    uint32_t part2 = rand() & (RAND_MAX - 1);
     88    uint32_t part3 = rand() & (RAND_MAX - 1);
     89    uint32_t part4 = rand() & (RAND_MAX - 1);
     90    // rand only provides 15 bits on Win32
     91    uint64_t fullRandom = part1;
     92    fullRandom <<= 15;
     93    fullRandom |= part2;
     94    fullRandom <<= 15;
     95    fullRandom |= part3;
     96    fullRandom <<= 15;
     97    fullRandom |= part4;
     98
     99    // Mask off the low 53bits
     100    fullRandom &= (1LL << 53) - 1;
     101    return static_cast<double>(fullRandom)/static_cast<double>(1LL << 53);
    85102#else
    86103    uint32_t part1 = rand() & (RAND_MAX - 1);
Note: See TracChangeset for help on using the changeset viewer.