BSONObj JSSrand( const BSONObj &a, void* data ) { uassert( 12518, "srand requires a single numeric argument", a.nFields() == 1 && a.firstElement().isNumber() ); #if !defined(_WIN32) _randomSeed.set( static_cast< unsigned int >( a.firstElement().numberLong() ) ); // grab least significant digits #else srand( static_cast< unsigned int >( a.firstElement().numberLong() ) ); #endif return undefinedReturn; }
BSONObj JSSrand(const BSONObj& a, void* data) { unsigned int seed; // grab the least significant bits of either the supplied argument or // a random number from SecureRandom. if (a.nFields() == 1 && a.firstElement().isNumber()) seed = static_cast<unsigned int>(a.firstElement().numberLong()); else { std::unique_ptr<SecureRandom> rand(SecureRandom::create()); seed = static_cast<unsigned int>(rand->nextInt64()); } #if !defined(_WIN32) _randomSeed.set(seed); #else srand(seed); #endif return BSON("" << static_cast<double>(seed)); }
StackChecker() { checker.set(this); }