- Prevent a clipping of values when converting a double to an unsigned int for use as the random generator's seed value. Review URL: http://codereview.chromium.org/1887 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@246 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
This commit is contained in:
parent
10398b692e
commit
0157bcd8f8
@ -67,7 +67,12 @@ double ceiling(double x) {
|
||||
|
||||
void OS::Setup() {
|
||||
// Seed the random number generator.
|
||||
srandom(static_cast<unsigned int>(TimeCurrentMillis()));
|
||||
// Convert the current time to a 64-bit integer first, before converting it
|
||||
// to an unsigned. Going directly can cause an overflow and the seed to be
|
||||
// set to all ones. The seed will be identical for different instances that
|
||||
// call this setup code within the same millisecond.
|
||||
uint64_t seed = static_cast<uint64_t>(TimeCurrentMillis());
|
||||
srandom(static_cast<unsigned int>(seed));
|
||||
}
|
||||
|
||||
|
||||
|
@ -73,7 +73,12 @@ double ceiling(double x) {
|
||||
|
||||
void OS::Setup() {
|
||||
// Seed the random number generator.
|
||||
srandom(static_cast<unsigned int>(TimeCurrentMillis()));
|
||||
// Convert the current time to a 64-bit integer first, before converting it
|
||||
// to an unsigned. Going directly will cause an overflow and the seed to be
|
||||
// set to all ones. The seed will be identical for different instances that
|
||||
// call this setup code within the same millisecond.
|
||||
uint64_t seed = static_cast<uint64_t>(TimeCurrentMillis());
|
||||
srandom(static_cast<unsigned int>(seed));
|
||||
}
|
||||
|
||||
|
||||
|
@ -493,7 +493,12 @@ char* Time::LocalTimezone() {
|
||||
|
||||
void OS::Setup() {
|
||||
// Seed the random number generator.
|
||||
srand(static_cast<unsigned int>(TimeCurrentMillis()));
|
||||
// Convert the current time to a 64-bit integer first, before converting it
|
||||
// to an unsigned. Going directly can cause an overflow and the seed to be
|
||||
// set to all ones. The seed will be identical for different instances that
|
||||
// call this setup code within the same millisecond.
|
||||
uint64_t seed = static_cast<uint64_t>(TimeCurrentMillis());
|
||||
srand(static_cast<unsigned int>(seed));
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user