0
0
mirror of https://github.com/mongodb/mongo.git synced 2024-11-30 00:56:44 +01:00

better randoms on OS X

This commit is contained in:
dwight 2009-01-18 12:19:26 -05:00
parent 644af22b4d
commit f7dcfc6a2c
2 changed files with 9 additions and 3 deletions

View File

@ -318,7 +318,7 @@ namespace mongo {
repairDatabases();
/* this is for security on certain platforms */
srand(curTimeMillis() ^ startupSrandTimer.micros());
srand(curTimeMicros() ^ startupSrandTimer.micros());
listen(listenPort);
}
@ -334,7 +334,7 @@ using namespace mongo;
int main(int argc, char* argv[], char *envp[] )
{
srand(curTimeMillis());
srand(curTimeMicros());
boost::filesystem::path::default_name_check( boost::filesystem::no_check );
{

View File

@ -14,6 +14,10 @@ namespace mongo {
#if defined(__linux__)
devrandom = new ifstream("/dev/urandom", ios::binary|ios::in);
massert( "can't open dev/urandom", devrandom->is_open() );
#elif defined(_WIN32)
srand(curTimeMicros());
#else
srandomdev();
#endif
assert( sizeof(nonce) == 8 );
@ -26,8 +30,10 @@ namespace mongo {
#if defined(__linux__)
devrandom->read((char*)&n, sizeof(n));
massert("devrandom failed", !devrandom->fail());
#else
#elif defined(_WIN32)
n = ((unsigned long long)rand())<<32 | rand();
#else
n = random();
#endif
return n;
}