File tree Expand file tree Collapse file tree 1 file changed +5
-17
lines changed Expand file tree Collapse file tree 1 file changed +5
-17
lines changed Original file line number Diff line number Diff line change 20
20
#include " swift/Runtime/Metadata.h"
21
21
#include " swift/Runtime/Debug.h"
22
22
#include < stdlib.h>
23
+ #include < random>
23
24
24
25
namespace swift {
25
26
// FIXME(ABI)#76 : does this declaration need SWIFT_RUNTIME_STDLIB_INTERFACE?
@@ -106,23 +107,10 @@ swift::_SwiftEmptySetStorage swift::_swiftEmptySetStorage = {
106
107
};
107
108
108
109
static __swift_uint64_t randomUInt64 () {
109
- #if defined(__APPLE__)
110
- return static_cast <__swift_uint64_t >(arc4random ()) |
111
- (static_cast <__swift_uint64_t >(arc4random ()) << 32 );
112
- #else
113
- auto devUrandom = fopen (" /dev/urandom" , " r" );
114
- if (!devUrandom) {
115
- swift::fatalError (/* flags = */ 0 , " Opening \" /dev/urandom\" failed" );
116
- }
117
- uint64_t result;
118
- if (fread (&result, sizeof (result), 1 , devUrandom) != 1 ) {
119
- swift::fatalError (/* flags = */ 0 , " Reading from \" /dev/urandom\" failed" );
120
- }
121
- if (fclose (devUrandom)) {
122
- swift::fatalError (/* flags = */ 0 , " Closing \" /dev/urandom\" failed" );
123
- }
124
- return result;
125
- #endif
110
+ std::random_device randomDevice;
111
+ std::mt19937_64 twisterEngine (randomDevice ());
112
+ std::uniform_int_distribution<__swift_uint64_t > distribution;
113
+ return distribution (twisterEngine);
126
114
}
127
115
128
116
SWIFT_ALLOWED_RUNTIME_GLOBAL_CTOR_BEGIN
You can’t perform that action at this time.
0 commit comments