Changeset 40937 in webkit for trunk/JavaScriptCore/wtf
- Timestamp:
- Feb 12, 2009, 2:28:17 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/wtf/RandomNumber.cpp
r40935 r40937 47 47 #endif 48 48 49 uint64_t fullRandom;50 49 #if COMPILER(MSVC) && defined(_CRT_RAND_S) 51 uint32_t part1;52 rand_s(& part1);53 fullRandom = part1;50 uint32_t bits; 51 rand_s(&bits); 52 return static_cast<double>(bits) / (static_cast<double>(std::numeric_limits<uint32_t>::max()) + 1.0); 54 53 #elif PLATFORM(DARWIN) 55 fullRandom = arc4random(); 54 uint32_t bits = arc4random(); 55 return static_cast<double>(bits) / (static_cast<double>(std::numeric_limits<uint32_t>::max()) + 1.0); 56 56 #elif PLATFORM(UNIX) 57 57 uint32_t part1 = random() & (RAND_MAX - 1); 58 58 uint32_t part2 = random() & (RAND_MAX - 1); 59 59 // random only provides 31 bits 60 fullRandom = part1;60 uint64_t fullRandom = part1; 61 61 fullRandom <<= 31; 62 62 fullRandom |= part2; 63 64 // Mask off the low 53bits 65 fullRandom &= (1LL << 53) - 1; 66 return static_cast<double>(fullRandom)/static_cast<double>(1LL << 53); 63 67 #else 64 68 uint32_t part1 = rand() & (RAND_MAX - 1); … … 71 75 fullRandom <<= 27; 72 76 fullRandom |= part2; 73 #endif 77 74 78 // Mask off the low 53bits 75 79 fullRandom &= (1LL << 53) - 1; 76 80 return static_cast<double>(fullRandom)/static_cast<double>(1LL << 53); 81 #endif 77 82 } 78 83
Note:
See TracChangeset
for help on using the changeset viewer.